Commits

Jérôme Vuarand committed f40d624

Fixes serialization for very small numbers (again, actually the previous fix was for numbers with many digits).

  • Participants
  • Parent commits 736ba0e

Comments (0)

Files changed (1)

 		elseif v==math.floor(v) then
 			return write(tostring(v))
 		else
-			return write(string.format('%.18f', v):gsub('(%..-)0*$', '%1'))
+			local s = string.format('%.18f', v):gsub('(%..-)0*$', '%1')
+			if tonumber(s)~=v then
+				s = string.format("%.13a", v)
+			end
+			return write(s)
 		end
 	elseif t=='boolean' then
 		if v then
 	local value = -0.00223606797749979
 	expect(value, tonumber(_M.tostring(value)))
 	
+	local value = 0.05 * math.cos(math.pi / 2)
+	assert(tonumber(tostring(value))~=value)
+	expect(value, tonumber(_M.tostring(value)))
+	
 	-- a complete file showing key ordering
 	local str = [[
 return {