Re: Separate Printing Mantissa and Exponent of a Floating Point

2014-08-13 Thread Nordlöw
On Monday, 11 August 2014 at 15:30:30 UTC, Justin Whear wrote: 1. http://dlang.org/phobos/std_bitmanip.html#.FloatRep Could someone briefly outline the algorithm that converts the fraction part of FloatRep into a string in base 10? My first guess is sum = 0; foreach (bit_index i,

Re: Separate Printing Mantissa and Exponent of a Floating Point

2014-08-13 Thread Nordlöw
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

Separate Printing Mantissa and Exponent of a Floating Point

2014-08-11 Thread Nordlöw
Is there a way to separately stringify/print the mantissa and exponent of a floating point? I want this in my pretty-printing module to produce something like 1.2 \cdot 10^3 instead of 1.2e3 I could of course always split on the e but that is kind of non-elegant, I believe.

Re: Separate Printing Mantissa and Exponent of a Floating Point

2014-08-11 Thread Nordlöw
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]

Re: Separate Printing Mantissa and Exponent of a Floating Point

2014-08-11 Thread Justin Whear via Digitalmars-d-learn
On Mon, 11 Aug 2014 13:47:13 +, Nordlöw wrote: Is there a way to separately stringify/print the mantissa and exponent of a floating point? I want this in my pretty-printing module to produce something like 1.2 \cdot 10^3 instead of 1.2e3 I could of course always split on the

Re: Separate Printing Mantissa and Exponent of a Floating Point

2014-08-11 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
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 ==

Re: Separate Printing Mantissa and Exponent of a Floating Point

2014-08-11 Thread Nordlöw
On Monday, 11 August 2014 at 15:37:29 UTC, Dominikus Dittes Scherkl wrote: Should be patrs[1], he? No, parts[1] contains a slice to the e separating the mantissa from the exponent.

Re: Separate Printing Mantissa and Exponent of a Floating Point

2014-08-11 Thread Nordlöw
On Monday, 11 August 2014 at 15:30:30 UTC, Justin Whear wrote: 1. http://dlang.org/phobos/std_bitmanip.html#.FloatRep Great! Thx.

Re: Separate Printing Mantissa and Exponent of a Floating Point

2014-08-11 Thread Nordlöw
On Monday, 11 August 2014 at 15:30:30 UTC, Justin Whear wrote: 1. http://dlang.org/phobos/std_bitmanip.html#.FloatRep I'm lacking a use case. See http://dlang.org/library/std/bitmanip/FloatRep.html Is unsafe *(cast(FloatRep*)float_instance) the only way to use this?