Skip to content

Instantly share code, notes, and snippets.

@ladc
Created January 28, 2015 09:53
Show Gist options
  • Save ladc/37f5f0ff2430750f80fb to your computer and use it in GitHub Desktop.
Save ladc/37f5f0ff2430750f80fb to your computer and use it in GitHub Desktop.
local v1 = 1-5e-9
local v2 = 1-5e-9-1e-16
local function sprintf(...)
io.write(string.format(...))
end
print("13 hex digits define a double, so these numbers are almost identical:")
sprintf("%.13a\n",v1)
sprintf("%.13a\n",v2)
print("However their \"%.8g\" representation is still different:")
sprintf("%.8g\n",v1)
sprintf("%.8g\n",v2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment