Floating point formats and isinf ()

I am currently dealing with floating point values ​​in C ++. Consider the following C ++ snippet:

#include <cmath>
#include <cstring>
#include <iostream>

int main() {
    long double num;

    // Set num to a large, valid, floating point value
    memset(&num, 0xcc, sizeof(num));

    std::cout << "num = " << num << std::endl;
    std::cout << "isinf(num) = " << isinf(num) << std::endl;
    std::cout << "std::isinf(num) = " << std::isinf(num) << std::endl;

    return 0;
}

According to Wikipedia , this creates an 80 bit extended floating point precision since I use GCC on an x86 machine. Therefore, the floating point value 0xcccc cccc cccc cccc ccccmust be valid.

Interestingly, the output is as follows:

num = -4.77987e+986
isinf(num) = 1
std::isinf(num) = 0

This makes me wonder:

  • Why behavior isinfand std::isinfdifferent? And which one is trustworthy?
  • , C99 isinf , ++ 11 . , , . -std=c++98, . std::isinf?
  • , , /?
+4
1

isinf, cmath, C, double. long double double . double +inf ( , , , , DBL_MAX, +inf).

std::isinf long double. long double, , std::isinf , .


:

  • , isinf . , , , #undef . , ( double).

  • DBL_MAX LDBL_MAX float.h/cfloat , (IEEE 754) 64- . , DBL_MANT_DIG LDBL_MANT_DIG, , , , 20 , ( 2017 ). sizeof(long double), 10, 12 16 80- , , , 16 .

+6

Source: https://habr.com/ru/post/1688216/


All Articles