C - Serialization of the floating point numbers (floats, doubles)

后端 未结 10 1055
攒了一身酷
攒了一身酷 2020-11-28 11:18

How to convert a floating point number into a sequence of bytes so that it can be persisted in a file? Such algorithm must be fast and highly portable. It must allow also th

10条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 11:50

    What do you mean, "portable"?

    For portability, remember to keep the numbers within the limits defined in the Standard: use a single number outside these limits, and there goes all portability down the drain.

    double planck_time = 5.39124E-44; /* second */
    

    5.2.4.2.2 Characteristics of floating types

    [...]
    10   The values given in the following list shall be replaced by constant
         expressions with implementation-defined values [...]
    11   The values given in the following list shall be replaced by constant
         expressions with implementation-defined values [...]
    12   The values given in the following list shall be replaced by constant
         expressions with implementation-defined (positive) values [...]
    [...]
    

    Note the implementation-defined in all these clauses.

提交回复
热议问题