question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add `.finite()` for numbers? Or require numbers to be finite by default?

See original GitHub issue

Usually, 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:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
kmbtcommented, Jan 16, 2022

I understand your point and do agree that excluding NaN from z.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 get Infinity 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.

3reactions
FlorianWendelborncommented, Jul 1, 2022

@stale bump

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found