Thread overview
exponential errors
May 08
NonNull
May 08
Dennis
May 08

I'm not the sharpest tool in the shed so I would really appreciate some assistance clarifying what's going on here and how to accomplish this seemingly simple (to me) goal.

I'd like to raise a floating point value d to some exponent n.

Never thought I'd have to do this but, in Python:

pow(1/2, 3)

output:

 0.125

in D:

import std.stdio;
void main()
{
  writeln((1/2)^^3);
}

Compile Time Error:

hist.d(40): Error: undefined identifier `pow` in module `std.math`

Say what? I don't remember ever calling import std.math : pow. Why am I getting this error?

Okay, whatever, just import the damn thing

import std.stdio;
void main()
{
  writeln((1/2)^^3);
  import std.math.exponential: pow;  // placement intentional, ran into this error
                                     // by accident while trying to understand the
                                     // error above and the one to come next at the
                                     // same time
}

Compile Time Error:

/Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(47): Error: version `InlineAsm_X86_Any` defined after use

Come again? Okay, good to know I guess. Let's get it right this time.

import std.stdio;
void main()
{
  import std.math.exponential: pow;
  writeln((1/2)^^3);
  // I was actually trying to use pow() here directly
  // which produced the same errors as below when I ran into the
  // previous error
}

Compile Time Error:

    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3791): Error: number `0x0.8p-126f` is not representable as a `float`
    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3791):        https://dlang.org/spec/lex.html#floatliteral
    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3791): Error: number `0x0.8p-126f` is not representable as a `float`
    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3791):        https://dlang.org/spec/lex.html#floatliteral
    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3793): Error: number `0x0.555556p-126f` is not representable as a `float`
    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3793):        https://dlang.org/spec/lex.html#floatliteral
    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3793): Error: number `0x0.555556p-126f` is not representable as a `float`
    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3793):        https://dlang.org/spec/lex.html#floatliteral
    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3804): Error: number `0x0.8p-1022` is not representable as a `double`
    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3804):        `real` literals can be written using the `L` suffix. https://dlang.org/spec/lex.html#floatliteral
    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3804): Error: number `0x0.8p-1022` is not representable as a `double`
    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3804):        `real` literals can be written using the `L` suffix. https://dlang.org/spec/lex.html#floatliteral
    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3806): Error: number `0x0.5555555555555p-1022` is not representable as a `double`
    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3806):        `real` literals can be written using the `L` suffix. https://dlang.org/spec/lex.html#floatliteral
    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3806): Error: number `0x0.5555555555555p-1022` is not representable as a `double`
    /Users/confuzzled/dlang/dmd-2.103.0/osx/bin/../../src/phobos/std/math/exponential.d(3806):        `real` literals can be written using the `L` suffix. https://dlang.org/spec/lex.html#floatliteral

I'm sorry, what am I missing? How do I accomplish this task?

-- anonymouse

May 08

On Monday, 8 May 2023 at 03:22:02 UTC, anonymouse wrote:

Sorry, I thought I was already in the Learn forum. Please move there if possible.

May 08

On Monday, 8 May 2023 at 03:22:02 UTC, anonymouse wrote:

>

Never thought I'd have to do this but, in Python:

pow(1/2, 3)

output:

 0.125

in D:

import std.stdio;
void main()
{
  writeln((1/2)^^3);
}

Using DMD64 D Compiler v2.103.0:

The above program ran and output 0 because 1/2 is zero in D as that's integer division. Putting 1.0 instead of 1, it output 0.125.

Your compiler version is?

May 08

On Monday, 8 May 2023 at 04:13:11 UTC, NonNull wrote:

>

On Monday, 8 May 2023 at 03:22:02 UTC, anonymouse wrote:

>

Never thought I'd have to do this but, in Python:

pow(1/2, 3)

output:

 0.125

in D:

import std.stdio;
void main()
{
  writeln((1/2)^^3);
}

Using DMD64 D Compiler v2.103.0:

The above program ran and output 0 because 1/2 is zero in D as that's integer division. Putting 1.0 instead of 1, it output 0.125.

Your compiler version is?

Fare enough regarding integer division, I used 1/2 in python when I switch to check my sanity and carried it forward when I came back to D but the results were the exact same. Errors vice the outputs you posted above. The actual code that triggered this was

double d = 0.5;
int n = 3;
writeln(d ^^ n);

As for the version of D I'm using, according to dmd --version it is none other than

DMD64 D Compiler v2.103.0

Not sure if it makes a difference but I'm using MacOS Ventura.

May 08

On Monday, 8 May 2023 at 04:31:37 UTC, anonymouse wrote:

>
As for the version of D I'm using, according to ```dmd --version``` it is none other than

DMD64 D Compiler v2.103.0

Not sure if it makes a difference but I'm using MacOS Ventura.

Removed and install v2.103.1, but experiencing the exact same issues.

May 08

On Monday, 8 May 2023 at 04:31:37 UTC, anonymouse wrote:

>

As for the version of D I'm using, according to dmd --version it is none other than

DMD64 D Compiler v2.103.0

Not sure if it makes a difference but I'm using MacOS Ventura.

This is a macOS issue. Don't know if it's specific to Ventura but I just loaded up a Debian VM and it runs as expected.

May 08

On Monday, 8 May 2023 at 05:01:44 UTC, anonymouse wrote:

>

This is a macOS issue. Don't know if it's specific to Ventura but I just loaded up a Debian VM and it runs as expected.

Indeed. Apparently Apple changed their floating point parsing function in their C runtime library, causing dmd to fail to parse certain floating pointing numbers in std.math. See issue https://issues.dlang.org/show_bug.cgi?id=23846.

It has been fixed, but you'll need to update to 2.104.0 which is currently in beta.

May 08

On Monday, 8 May 2023 at 10:24:53 UTC, Dennis wrote:

>

It has been fixed, but you'll need to update to 2.104.0 which is currently in beta.

Confirmed. installed 2.104.0-beta.1 and everything's now back to normal.

Thank you.

-- anonymouse