+ 1

floating point number systems in calculator app

is it good practice to use another Floating-Point Arithmetic for a calculator app.( i mean creating another arithmetic system) IEEE 754 have some issues such as losing accuracy, returns wrong result in some arithmetic operations. it seems in IEEE "speed" more important than "accuracy"

8th Aug 2021, 1:01 PM
Mehran
Mehran - avatar
2 ответов
+ 1
All binary floating point formats will inherently have some "inaccuracy", that's unavoidable. After all, the system is basically taking halves, ie 2^-n, where n is the nth bit of the fractional portion of a floating point number. You could eat half of a candy bar forever (until you hit individual atoms, then you would stop), and you'll still have half left over. Let's use an example. Suppose we want to convert 1.532 to a 32 bit IEEE 754 floating point number. We start with a fixed point number to represent this with 1 starting it for one whole value: 1.xxxxxx.... now, we go down the line of fractional bits by subtracting their place value from the decimal value of the original decimal number: 0.532 - 2^-1 = 0.532 - 0.500 = 0.032 (1.1xxxx.... is what we have now) 0.032 - 2^-2 = 0.032 - 0.250 = not possible, so 0 (1.10xxxx....) 0.032 - 2^-3 = 0.032 - 0.125 = not possible, so 0 (1.100xxxxx....) 0.032 - 2^-4 = 0.032 - 0.0625 = not possible, so 0 (1.1000xxxx) 0.032 - 2^5 = 0.032 - 0.03125 = 0.00075, so 1 (1.10001xxxx.....)..... and so on and so forth, until you wind up with the resulting IEEE 754 value (after format conversion) of: 0 01111111 10001000001100010010011 sign exponent (biased at 128) mantissa which equates to decimal as: 1.53199994564056396484375 This slight precision error is simply a downside to the binary floating point system. No matter how many bits you add to it, it will still have this error, though the more you add, the closer it will get to the actual answer. So to correct a bit of a misconception you have, no, it's not the fault of IEEE 754 that floating point numbers have imprecise values, rather it's the binary system it rests on. Now, to answer your actual question. Yes, there are other formats you can use for calculators, some of which use Binary Coded Decimal (BCD) to perform calculations with high degrees of precision. They have extremely complicated circuits, however.
8th Aug 2021, 2:15 PM
BootInk
BootInk - avatar
8th Aug 2021, 2:16 PM
Angelo
Angelo - avatar