against enforce
Steven Schveighoffer
schveiguy at yahoo.com
Mon Mar 28 05:52:53 PDT 2011
On Sat, 26 Mar 2011 08:14:19 -0400, Kagamin <spam at here.lot> wrote:
> Steven Schveighoffer Wrote:
>
>> For example, if I do:
>>
>> sqrt(1);
>>
>> There is never ever a need to test this in production code. sqrt(1) is
>> always 1, and will always work.
>>
>> If I do:
>>
>> sqrt(-1);
>>
>
> pure function called on literals is evaluatable at compile time together
> with checks, so if sqrt run at runtime, this means input couldn't be
> validated that easily, so checks should be run too. This means that it's
> unnecessary to ever remove checks from sqrt.
It's not that simple.
for example:
sqrt(uniform(1.0, 2000.0));
This is completely safe, and needs no runtime error checks.
It's easier to explain with simple examples, knowing that you can
extrapolate more complex ones that the compiler can't "prove".
-Steve
More information about the Digitalmars-d
mailing list