0
I’m a beginner so there might be some wrong things here.
I need to do thousands of calculations with data (decimal float numbers) from several giant csv files, so I figured using direct binary in ieee754 pattern would avoid conversion and this would save time.
That was my test:
#include <stdio.h>
int main()
{
float a = 0b00111111110000000000000000000000; /* 1.5 */ /* uint32_t !? */
float b = 0b00111111110000000000000000000000; /* 1.5 */ /* uint32_t !? */
float c;
c = a + b; /* 3.0 !? */
printf("a: %f\n", a);
printf("b: %f\n", b);
printf("a+b: %f\n", c);
return 0;
}
He returns to me:
a: 1069547520.000000
b: 1069547520.000000
a+b: 2139095040.000000
I realized the value is whole, it seems to me I should use uint32_t
, it summed the two integer values that returned 2139095040
.
That value 2139095040
who returned left me confused he is ieee754? can convert to decimal 3.0
I was hoping to return the standard binary iee754 01000000010000000000000000000000
and so could convert to decimal again.
Finally, how can I use ieee754 binary data to perform arithmetic operations and return the resulting value of this operation in binary and decimal in order to achieve more processing speed?
*How to do arithmetic operations using directly binary in c (was convert is wrong sorry, can not change after posted)
– Fabio Fontes
Isn’t that what you’re trying to do, why write in binary? In the code you just get a headache, if it is a read data from somewhere you will need to do conversion and it will be much slower. Don’t try to do something you don’t know. Forget it, do the simple and be happy. And I hope that those values are not monetary or that they need accuracy. Take a look here because I talk in various places about this crazy thing that people are putting into the head that there is binary or non-binary number, there is number, just this, the way you write it doesn’t matter, use easy.
– Maniero
cannot change after posting - just click on the link edit and make the changes. And by complementing Maniero’s comment, binary numbers are not "binary", they can be represented in binary form. A number is just a value. Ex: the number 3 represents only the value 3 (the idea of a quantity, "3 things"). This value can be represented in several ways: as the symbol (digit)
3
, in torque (base 2)11
, as the wordtrês
(orsix
in English, or三
in Japanese, etc). The representation changes but the value is the same.– hkotsubo
@hkotsubo ok worked
– Fabio Fontes