Separate Printing Mantissa and Exponent of a Floating Point

"Nordlöw" via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 13 00:58:39 PDT 2014


On Wednesday, 13 August 2014 at 07:51:30 UTC, Nordlöw wrote:
>> 1. http://dlang.org/phobos/std_bitmanip.html#.FloatRep

Can somebody shortly explain why

import std.stdio, std.algorithm, std.range, std.stdio, 
std.bitmanip;

void main(string args[])
{
     {
         float x = 1.23e10;
         auto y = *cast(FloatRep*)(&x);
         writeln(y.fraction, ", ",
                 y.exponent, ", ",
                 y.sign);
     }

     {
         double x = 1.23e10;
         auto y = *cast(DoubleRep*)(&x);
         writeln(y.fraction, ", ",
                 y.exponent, ", ",
                 y.sign);
     }
}

prints

3623111, 160, false
1945142772629504, 1056, false


More information about the Digitalmars-d-learn mailing list