digitalmars.D.learn - Initializing floating point types with explicit mantisa and exponent

=?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
```How do I best initialize a D double to an exact mantissa and
exponent representation?

I'm specifically interested in

2^^i for all i in [min_exp, max_exp]
```
Jan 16 2017
pineapple <meapineapple gmail.com> writes:
```On Tuesday, 17 January 2017 at 00:08:24 UTC, Nordlöw wrote:
How do I best initialize a D double to an exact mantissa and
exponent representation?

I'm specifically interested in

2^^i for all i in [min_exp, max_exp]

This mach module can do the job:
https://github.com/pineapplemachine/mach.d/blob/master/mach/math/floats/inject.d
```
Jan 16 2017
Nicholas Wilson <iamthewilsonator hotmail.com> writes:
```On Tuesday, 17 January 2017 at 00:08:24 UTC, Nordlöw wrote:
How do I best initialize a D double to an exact mantissa and
exponent representation?

I'm specifically interested in

2^^i for all i in [min_exp, max_exp]

See

std.bitmanip : FloatRep , DoubleRep;
```
Jan 16 2017
kinke <noone nowhere.com> writes:
```On Tuesday, 17 January 2017 at 00:08:24 UTC, Nordlöw wrote:
How do I best initialize a D double to an exact mantissa and
exponent representation?

I'm specifically interested in

2^^i for all i in [min_exp, max_exp]

If it doesn't have to be D ;), it can be as simple as
`core.stdc.math.ldexp(1, exponent)`. No CTFE though.
```
Jan 17 2017
=?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
```On Tuesday, 17 January 2017 at 16:40:57 UTC, kinke wrote:
If it doesn't have to be D ;), it can be as simple as
`core.stdc.math.ldexp(1, exponent)`. No CTFE though.

Isn't it a simple as

2.0^^exponent

?
```
Jan 17 2017
kinke <noone nowhere.com> writes:
```On Tuesday, 17 January 2017 at 17:56:13 UTC, Nordlöw wrote:
On Tuesday, 17 January 2017 at 16:40:57 UTC, kinke wrote:
If it doesn't have to be D ;), it can be as simple as
`core.stdc.math.ldexp(1, exponent)`. No CTFE though.

Isn't it a simple as

2.0^^exponent

?

It should and I looked into that as well, but I didn't like the
implementation as loop:
https://github.com/dlang/phobos/blob/master/std/math.d#L5988

A special case for base x == 2 wouldn't hurt.
```
Jan 17 2017
=?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
```On Tuesday, 17 January 2017 at 18:25:46 UTC, kinke wrote:
It should and I looked into that as well, but I didn't like the
implementation as loop:
https://github.com/dlang/phobos/blob/master/std/math.d#L5988

A special case for base x == 2 wouldn't hurt.

That seems strange. Why isn't that a builtin behaviour for
operator ^^?
```
Jan 17 2017