lexyeevee

troublesome fox girl

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


You must log in to comment.

in reply to @lexyeevee's post:

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?

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