Home > Software engineering >  Why does storing 7 floating-point numbers need 34 bytes?
Why does storing 7 floating-point numbers need 34 bytes?

Time:04-15

I have a file that stores 7 numbers in double. See below. But its size is only 34 bytes. Shouldn't it be 7*8 = 56 bytes instead?

$ cat data
17.2
18.1
16.5
18.3
12.6
0.75
0.25$ ls -l data
-rw-r--r-- 1 root root 34 Apr 15 03:29 data

CodePudding user response:

The file contains text representations of the numbers (e.g. written out as digits with a decimal point and a newline separator) rather than as IEEE-754 floating point numbers. The byte count you’re seeing is for the number of characters used, not the number of bytes needed in IEEE-754 format.

  • Related