Complete NotANumber - #86
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #86 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 301 336 +35
=========================================
+ Hits 301 336 +35 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
PatrickHaecker
force-pushed
the
not_a_number
branch
from
September 4, 2026 13:48
01b5ce1 to
65682f0
Compare
Contributor
Author
|
Test coverage is now 100%. |
Contributor
Author
|
Working at |
PatrickHaecker
force-pushed
the
not_a_number
branch
3 times, most recently
from
September 6, 2026 06:21
8e5442b to
ecf62b0
Compare
Contributor
Author
|
Yes, this is more consistent. So changed accordingly. |
PatrickHaecker
force-pushed
the
not_a_number
branch
2 times, most recently
from
September 6, 2026 14:27
704b2c5 to
f0721a6
Compare
PatrickHaecker
force-pushed
the
not_a_number
branch
from
September 6, 2026 15:58
f0721a6 to
a2b3f31
Compare
Closed
PatrickHaecker
force-pushed
the
not_a_number
branch
from
September 7, 2026 03:48
a2b3f31 to
e809106
Compare
PatrickHaecker
force-pushed
the
not_a_number
branch
from
September 20, 2026 03:57
e809106 to
72bb227
Compare
added 4 commits
September 23, 2026 11:52
It satisfies `isnan`, compares false against everything including itself, keeps
`isequal` and `hash` so a container can hold one, sorts last, and converts to
the `NaN` of any float type.
It also becomes a `Real`. Dividing two real numbers has to give a real
number, and `+∞/+∞` is a `NotANumber`, so as a `Number` it made
`isreal(+∞/+∞)` false. The supertype is also what lets `Complex{NotANumber}`
exist, since `Complex` takes a `Real`.
The price is dispatch. A `Real` matches Base's own methods for `Real`, which
are exactly as specific, so every such slot has to be filled here.
`NotANumberRivals` lists the types that need one.
Every operation on it was a MethodError or an ErrorException, so an undefined result could not be carried any further.
Adding infinities of opposite direction and multiplying an infinity by zero threw an ArgumentError, where the floats give NaN. The mod case is left alone, since Base returns -2.0 for mod(-2.0, Inf) rather than NaN.
The float NaN was returned unchanged, keeping its precision, where every other float special value loses it: Inf32 + ∞ is already ∞. This reverses a tested line of the NaN arithmetic PR.
PatrickHaecker
force-pushed
the
not_a_number
branch
from
September 23, 2026 09:54
72bb227 to
a28f6ba
Compare
PatrickHaecker
marked this pull request as ready for review
September 23, 2026 09:56
Open
dlfivefifty
reviewed
Sep 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NotANumberexisted but could not really be used except as the value itself. Everyoperation on it was a
MethodErroror anErrorException, so an undefined resultcould not be carried any further. Most of the places that should have produced a
NotANumberthrew instead.The current PR makes it behave like a float
NaNinstead.It answers
isnan, compares false against everything including itself, keepsisequaland
hashso a container can hold one, sorts last, and converts to theNaNof anyfloat type. Every arithmetic operation propagates it.
It also becomes a
Real. Dividing two real numbers has to give a real number, and+∞/+∞is aNotANumber. Previously, it hadisreal(+∞/+∞)false.Realas supertype allowsComplex{NotANumber}, so an operation with a complexoperand answers
NotANumber() + NotANumber()*im, like the floats do.Behaviour that changes:
∞ + (-∞)and0 * ∞answerNotANumber()instead of throwing anArgumentError.NaN + ∞answersNotANumber()instead of the floatNaN. Every other float specialvalue already loses its precision here —
Inf32 + ∞is∞.isreal(NotANumber())istrue.modis deliberately left alone.Baseanswersmod(-2.0, Inf)with-2.0, notNaN,so
NotANumber()would be the wrong answer there;mod(x, ∞)keeps throwing as before.Based on #82, so it stays a draft until that is merged.