minimum double value in C/C++

后端 未结 10 1435
天命终不由人
天命终不由人 2020-12-04 08:41

Is there a standard and/or portable way to represent the smallest negative value (e.g. to use negative infinity) in a C(++) program?

DBL_MIN in float.h is the smalle

10条回答
  •  感动是毒
    2020-12-04 09:34

    Floating point numbers (IEEE 754) are symmetrical, so if you can represent the greatest value (DBL_MAX or numeric_limits::max()), just prepend a minus sign.

    And then is the cool way:

    double f;
    (*((long long*)&f))= ~(1LL<<52);
    

提交回复
热议问题