Positive
Michel Fortin
michel.fortin at michelf.com
Sun Oct 5 01:04:37 PDT 2008
On 2008-10-05 01:55:43 -0400, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> said:
> That will do a runtime check and throw if x is negative. That's
> unprecedented for an implicit cast, so I was thinking of defining a
> universal "unsigned" template function that does the check:
>
> auto y = sqrt(unsigned(x));
Well, at this point I would prefer if it was a contract. Having to
explicitly convert to unsigned just makes it harder than necessary.
Throwing may be unprecedented for implict casts, but it is standard for
contracts using assertions. So I think it would be okay to implicit
cast and assert the value is non-negative (which would be equivalent to
enforcing a contract).
But then, shouldn't sqrt(-1) give you NaN, or i?
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list