1 does not equal 1?
ThinkingBeanz opened this issue ยท 2 comments
Minecraft Version
1.18.x
Version
1.101.0
Details
I'm facing a weird bug. (31.36 * 64)/(44.8^2) should equal 1, but it doesnt?
I'm on version 1.18.2 of Minecraft, using CC:Tweaked version 1.101.0 on Forge version 40.1.84
printing (31.36 * 64) / (44.8 ^ 2) says 1, but when compared with 1 using the "==" operator, it prints "false".
My main issue is I'm trying to get the inverse sine of the number, but it returns "nan", even though it works if I input 1.
The main issue is I'm working on some sorta program that finds the angle given a distance from a cannon, but I get nan when trying to get an angle at the max range of the cannon given parameters. I am using the Create mod alongside Big Cannons, an addon for the Create mod.
The problem here is with IEEE 754 double-precision floating point numbers not being able to precisely represent some numbers.
You could try tonumber(tostring((31.36*64)/(44.8^2)))
. (The number gets rounded down to 1 when tostring
is called.)
Alternatively, keep it within the domain of math.asin
through using math.min
and math.max
: math.min(1, math.max(-1, (31.36*64)/(44.8^2)))