FauxPseudo @lemmy.world to Skeptic@lemmy.worldEnglish · 1 年前"Do your own research" they say.lemmy.worldimagemessage-square100fedilinkarrow-up1704arrow-down127
arrow-up1677arrow-down1image"Do your own research" they say.lemmy.worldFauxPseudo @lemmy.world to Skeptic@lemmy.worldEnglish · 1 年前message-square100fedilink
minus-squareEcho DotlinkfedilinkEnglisharrow-up4·1 年前2.25 + 2.25 = 4.5 If you add two floats together then the output is a float, if you add an int and a float together the output is a float. Computers will always perform the calculation as is, unless you explicitly tell them to perform a rounding operation.
minus-squarecynar@lemmy.worldlinkfedilinkEnglisharrow-up6·1 年前However, if you stuff them into an int at the last minute, you can get that effect. Under the hood, it’s floats. On the output, it’s ints. It’s obvious and silly with small examples. The problem can creep in when you are using larger libraries or frameworks.
2.25 + 2.25 = 4.5
If you add two floats together then the output is a float, if you add an int and a float together the output is a float. Computers will always perform the calculation as is, unless you explicitly tell them to perform a rounding operation.
However, if you stuff them into an int at the last minute, you can get that effect.
Under the hood, it’s floats. On the output, it’s ints.
It’s obvious and silly with small examples. The problem can creep in when you are using larger libraries or frameworks.