Is scientific notation safe for integer constants in C?

前端 未结 6 733
心在旅途
心在旅途 2021-02-03 18:04

For a while, I\'ve been representing large powers of 10 in constants using scientific notation, just so I don\'t have to count the zeros. e.g.

#define DELAY_USE         


        
6条回答
  •  执念已碎
    2021-02-03 18:35

    You ask specifically about powers of ten. 1e6 will be exactly one million. You can go up to 1e22 without anything bad happening. However, note that in both C++ and C, 1e6 is a double constant, rather than an integer constant.

    Negative powers of ten are a different story. 1e-1 is inexact, as are all lower powers.

提交回复
热议问题