Add `.finite()` for numbers? Or require numbers to be finite by default?
See original GitHub issueUsually, when I want a number, I want it to be finite.
I’d like to be able to say something like z.number().finite()
to represent numbers that can’t be Infinity
or -Infinity
.
Or, even better in my opinion (but a breaking change), I’d prefer that the default number implementation disallow non-finite values, so that z.number().parse(Infinity)
throws an error. I think it’d be consistent with rejecting Number.NaN
, since Infinity is a number-like thing in javascript that’s not really a number, and NaN
is already disallowed.
Would you accept a PR to make either of these changes?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:12 (4 by maintainers)
Top Results From Across the Web
is.finite: Finite, Infinite and NaN Numbers - Rdrr.io
Complex numbers are finite if both the real and imaginary parts are. ... The default methods accept character and raw vectors, and return...
Read more >Number.isFinite() - JavaScript - MDN Web Docs
The Number.isFinite() method determines whether the passed value is a finite number — that is, it checks that a given value is a...
Read more >Finite, Infinite and NaN Numbers - R
R object to be tested: the default methods handle atomic vectors. Details. is.finite returns a vector of the same length as x the...
Read more >Why isn't NaN finite? - Stack Overflow
As Dave Newton said, NaN is not a number, and then you have to consider that it isn't finite nor infinite. The same...
Read more >Is it possible to split the natural numbers into a finite number of ...
Now I simply take the number N=5×13×17×29, which can be written as the sum of two squares in many ways. Somewhere in the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I understand your point and do agree that excluding
NaN
fromz.number()
and requiring it to be specified explicitly by union can actually benefit most real-life use-cases and also help spot math errors.But then, by the same rationale, why include
Infinity
which can be a result of division by zero? I can’t remember the last time I wanted to getInfinity
passed anywhere either. Perhaps it should be removed then - for consistency.I also think that it would be good idea to put those values in the docs so that it would be made clear which of the possible values for
number
type are accepted and which are not.@stale bump