issue 7006 - std.math.pow (integral, integral) crashes on negative exponents
Johannes Loher
johannes.loher at fg4f.de
Mon Dec 16 12:25:11 UTC 2019
On Monday, 16 December 2019 at 06:44:31 UTC, Dominikus Dittes
Scherkl wrote:
> [...] And if its time critical and you need only integers,
> there are much faster solutions than using pow (e.g.
> odd(x)?-1:1 )
The thing is: In math, it is extremely common to write this as
(-1)^^x. I don‘t understand why we should not allow this
notation. As Timon explained, the restriction just makes no sense
and was not what he had expected (I am also very surprised by
this). I admit that Timon’s explanations sounded a bit harsh, but
that does not makes them any less true. This is simply an
arbitrary limitation. The definition of pow in math can be
perfectly adapted to integers by simply using integer division,
i.e. 2^^(-1) == 0, so this is how it should work.
More information about the Digitalmars-d
mailing list