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