std.xml validity checking is absurd

John Colvin john.loughran.colvin at gmail.com
Fri Feb 8 06:11:42 PST 2013


On Friday, 8 February 2013 at 13:33:43 UTC, bearophile wrote:
> Andrei Alexandrescu:
>
>> I don't think std.math.sqrt should validate its input using a 
>> contract.
>
> Why not? Returning a NaN is an option. But in a language that 
> supports contracts, its precondition should only accept 
> non-negative inputs.
>
> Bye,
> bearophile

Passing a negative number to sqrt is something that could well be 
an expected event in release code that works with real data.

A Nan is a convenient way of marking bad data (and anything 
calculated from that data) as being invalid without having to set 
up an exception framework that does the same job explicitly and 
inefficiently.

If sqrt used contracts, then that would make debug mode useless 
to a lot of data analysis programs that are designed (sensibly) 
to use NaNs.


More information about the Digitalmars-d mailing list