Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one test floating point representation for file storage? [duplicate]

I have scientific data dumped into files. At the moment I've just dumped them with the same representation as they are in memory. I have documented that they are IEEE754 but I would love to have this asserted in the code so that if it gets ported to a weird architecture and separated from my documentation (research codes get passed around) it errors on compilation. At the moment I have

static_assert(sizeof(double)==8), "message");

Is there a way to test IEEE754? And can that be static asserted?

like image 341
Cramer Avatar asked May 20 '15 05:05

Cramer


1 Answers

In C, check if this is defined:

__STDC_IEC_559__

In C++, check if this is true:

std::numeric_limits<double>::is_iec559()

IEC559, short for International Electrotechnical Commission standard 559,is the same as IEEE 754.

like image 101
Yu Hao Avatar answered Nov 06 '22 11:11

Yu Hao