Zero is positive?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Zero is positive?

Chris Muller-3
I was just found a bug in my code because I had written it assuming
that the number 0 (zero) is neither positive nor negative.  It failed
because:

   0 positive    "true"

Really?

Ah, okay, there's #strictlyPositive, I'll use that.

But it seems like #nonNegative might be a better name then!

Reply | Threaded
Open this post in threaded view
|

Re: Zero is positive?

Levente Uzonyi
Those methods conform to the ANSI standard. ;)

Levente

On Sat, 30 Jun 2018, Chris Muller wrote:

> I was just found a bug in my code because I had written it assuming
> that the number 0 (zero) is neither positive nor negative.  It failed
> because:
>
>   0 positive    "true"
>
> Really?
>
> Ah, okay, there's #strictlyPositive, I'll use that.
>
> But it seems like #nonNegative might be a better name then!

Reply | Threaded
Open this post in threaded view
|

Re: Zero is positive?

Bruce O'Neel-2
In reply to this post by Chris Muller-3
One imagines there has been bloodshed in standards meetings over things like this.

For example, IEEE 754 has both positive and negative zeros.

For those of you who don't feel that life is pedantic enough there are many fascinating articles.   You can start with:


and if you have way way too much time on your hands on a Sunday a C++ wg21 proposal edit from Apple.  Probably from someone who thought "Life is not complex enough, I'll volunteer for the CLANG team.  Oh, and then I'll join the standards committee as well."


cheers

bruce

30 June 2018 23:11 Chris Muller <[hidden email]> wrote:
I was just found a bug in my code because I had written it assuming
that the number 0 (zero) is neither positive nor negative. It failed
because:

0 positive "true"

Really?

Ah, okay, there's #strictlyPositive, I'll use that.

But it seems like #nonNegative might be a better name then!