issue 7006 - std.math.pow (integral, integral) crashes on negative exponents

Timon Gehr timon.gehr at gmx.ch
Tue Dec 17 15:56:12 UTC 2019


On 17.12.19 16:43, Patrick Schluter wrote:
> On Tuesday, 17 December 2019 at 14:29:58 UTC, Timon Gehr wrote:
>> On 17.12.19 15:02, Patrick Schluter wrote:
>>>
>>> Except for 0^^0 there is no reason to throw or crap out.
>>
>> 0^^0 = 1 and D gets this right already.
> 
> Not as clear cut as you say, but generally it is agreed upon being set 
> to 1.
> 
> https://en.wikipedia.org/wiki/Zero_to_the_power_of_zero
> ...

- Anyone can edit Wikipedia, and laymen like to preserve outdated 
conventions from 200 years ago that are sometimes taught in primary school.
- That article actually explains why a computer scientist must consider 
the value to be 1 if your domain of exponents models a discrete set. 
(Knuth says so!)
- Many other modern programming languages also get it right, even C99.
- D is sometimes proud to fix design mistakes in C++. Add this to the list.

> but to clarify what I meant
> 
> except for 0^0 where an exception could be justified,

It can't be justified. The reason IEEE 754 supports multiple 
conventions, with 1 being the default, is that floats are often used to 
approximately model continuous functions and an exact value of 0 could 
be the result of a rounding error.

> all other cases have no reason to even contemplate throwing an exception.

0^^-1.



More information about the Digitalmars-d mailing list