> print(352.00000000001, 352.00000000001-352)
352.00000000001 1.0004441719502e-11
> print(352.000000000001, 352.000000000001-352)
352 1.0231815394945e-12
> print(352.0000000000001, 352.0000000000001-352)
352 1.1368683772162e-13
thanks lua
hello i like to make video games and stuff and also have a good time on the computer. look @ my pinned for some of the video games and things. sometimes i am horny on @squishfox
> print(352.00000000001, 352.00000000001-352)
352.00000000001 1.0004441719502e-11
> print(352.000000000001, 352.000000000001-352)
352 1.0231815394945e-12
> print(352.0000000000001, 352.0000000000001-352)
352 1.1368683772162e-13
thanks lua
Lua doesn't implement any number formatting itself, it passes everything to C's printf-style functions for formatting (using the format %.14g, I believe, which is also popular in other languages)
I'm not sure what you'd prefer Lua/C to do here, given the limitations of floating-point numbers?
Hmm, and the parsing should just be a sscanf... so I guess this is behavior mandated by ISO C (and possibly IEEE754?)
formatting with fewer significant digits than the type can hold is certainly not mandated by anything
the choice of format is lua doing number formatting. none of python, js, ruby, or haskell truncate here
i would prefer float formatting to be injective!
i dont know what any of those numbers means but they are indeed numbers
watch out the overexplainer has logged on:
all numbers in lua are in a format called "double-precision floating point". the specifics here aren't too important, but the important thing here is that most numbers with a decimal point in them will be represented "approximately". so 352.00000000001 isn't actually that number exactly, it's more like a binary number and how exact it is depends on how well that series of base-10 digits divides into a binary base-2.
doing 352.<<your digits>>> - 352 will return only the decimal part, so you can see how off and weird it was. this is where the random-seeming digits are coming from on the right side, that's the "floating-point error". the left side, however, is LYING. it's hiding the fact that those digits are there, specifically because the lua developers wanted the numbers to look more normal.
therefore
awesome i love pretending numbers are the same when they aren't
this is not on the floats, lua is showing two floats being the same when they aren't