Separate Printing Mantissa and Exponent of a Floating Point

Dominikus Dittes Scherkl via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 11 08:37:28 PDT 2014


On Monday, 11 August 2014 at 14:15:05 UTC, Nordlöw wrote:
> Here's my current try:
>
> string toMathML(T)(T x) @trusted /** pure */ if 
> (isFloatingPoint!T)
> {
>     import std.conv: to;
>     import std.algorithm: findSplit; //
>     immutable parts = to!string(x).findSplit("e");
>     if (parts[2].length == 0)
>         return parts[0];
>     else
>         return parts[0] ~ "*10^" ~ parts[2];
> }
Should be patrs[1], he?

I had the same problem, but not for printing, but to do some math 
on them.
Unfortunately math.h uses this internal (e.g. in trunc()) but 
doesn't give it to outside.
I think it would be a good abstaction between the 
hardware-realated stuff and the interface - at the moment almost 
the same code is repeated three times over math.h always with the 
same version switches.


More information about the Digitalmars-d-learn mailing list