Why does is_positive for a integer return false for 0?

0 is generally considered to be positive unless there's something i'm missing.

can you give example's of languages/libs etc?
imho "positive" is generally considered "greater than 0" as far as i always assumed... :slight_smile:

edit: this might be culturally biased though as i now discovered? quoting uncle G:

French (and some other romance/European math traditions): In French mathematical conventions, positif ("positive") often means non-negative (≥ 0), so 0 is considered both positive and negative (à la fois positif et négatif).

jokes incoming in 3, 2... (light-hearted fun, feel free to flag me if offensive :wink: )

According to Wikipedia, there are multiple definitions, one where zero is neither positive or negative, and one where zero is both positive and negative.

However, as far as I know, most programming languages define the integer (not float) 0 to be neither positive nor negative, and Rust follows this convention.

If you were to retrieve the sign bit, it would be asymmetric, following the nature of two's complement arithmetic: 0 has a sign bit of 0, as do all positive numbers, and only numbers less than 0 have a sign bit of 1. But two’s complement arithmetic is also asymmetric in its range; e.g. i8 has the range −128 to +127. The extra negative-sign-bit value −128 balances out the extra positive-sign-bit value 0.

given that different groups of people have different definitions of "positive", naming a function is_positive seems like a mistake to me,

the majority of people (myself included) would likely look at that name and think "that's so self-descriptive, i won't need to read the docs to understand what it does",
not realising that there are multiple definitions of positive.


slightly unrelated, but I hope I won't ever fail a math test somewhere just because I used the wrong definition of positive on accident :ferris_melt:.

I believe the vast majority of the world uses "positive" to mean > 0. French mathematics might be the only exception.

Similarly, "greater than" normally means > for most people, but for French people it means >=, and > is "strictly greater than".

What is weird to me is that "an increasing function" often takes on the French meaning (i.e. constant is increasing) in English literature. But I don't think this happens for positive or greater than.

A quick google around shows that mathematicians are very confused about this :slight_smile:

Things have been clear in computer world since the adoption of twos complement representation of integers. If the sign bit is clear it's positive, which includes zero.

I conclude that for a systems programming language is_positive() is a fine name. Anything else would have confused me...