Fraction function

BlitzMax Forums/BlitzMax Beginners Area/Fraction function

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Nope, it's not print specific, and it's not a problem with your functions. Floating point values are only accurate to a certain number of decimal places. This is because it is not possible to store all decimal fractions exactly in binary format. (Trying to express 1/3 or 2/3 in decimal is similar - you can't do it exactly for infinite decimal places).

For most purposes I'd say 0.93 being represented as 0.9299999 is accurate enough for even important calculations, unless you are doing something which is needs to be extremely accurate. In that case you will need to find an alternate method. For example, store the fraction part as an integer along with an (inverse) exponent.

For example, 1.2 would be stored as 2 with an exponent 10, meaing you must divide 2 by 10 to get the desired .2 . This will represent the value accurately for display or storage, but when you use it into a calcuation it will just be used as the floating point value again.

But I think you'll find the inaccuracy is negligible. Try it ;)