0

The Stable Pseudo Code is this mentioned on the following link. I would like to implement it in c++. I am not able to understand and perform these signof and exponentof and mantissaof operations.

how to convert double between host and network byte order?

void htond (const double hostDouble, uint8_t result[8])
{
  result[0] = signOf(hostDouble);
  result[1] = exponentOf(hostDouble);
  result[2..7] = mantissaOf(hostDouble);
}
Community
  • 1
  • 1
Hiesenberg
  • 415
  • 1
  • 8
  • 12

1 Answers1

0

To get the sign (even for negative zeros) use std::signbit().

To extract the exponent, use std::frexp() (or std::ilogb() for non-power-of-two radix). Note that you have to handle zero, infinity and NaN as special cases.

The mantissa can be obtained with std::abs(std::ldexp(value, -exponent)) (or std::scalbn() for a non-power-of-two radix); this will produce a fraction normalized (with a range depending on what function you used to extract the exponent).

DanielKO
  • 4,422
  • 19
  • 29