Page 1 of 1
NaN and Infinity
Posted: Wed Jul 17, 2019 11:30 pm
by Clyde
Hi there,
currently I am porting some lua code to Hollywood. In this code there are checks if a number is NaN (not a number) and infinity, like so:
Code: Select all
val ~= val -- checks for NaN -> "We rely on the property that NaN is the only value that doesn't equal itself." (see http://lua-users.org/wiki/InfAndNanComparisons)
val >= math.huge
The first line could be easily transformed to val <> val. But is this legit or neccessary in Hollywood? Does NaN "exist" in Hollywood?
And what about the second line, checks agains infinity? Is that possible in Hollywood?
Thanks in advance!
Re: NaN and Infinity
Posted: Fri Jul 19, 2019 10:39 am
by Clyde
*push*

Re: NaN and Infinity
Posted: Mon Jul 22, 2019 5:52 pm
by airsoftsoftwair
Nice spot, this is currently not possible without going to greater pains because in comparison to Lua, Hollywood won't allow you to divide by zero. I have now added some functions which allow you to deal with all those things:
Code: Select all
- New: Added RawDiv(); this does the same as Div() but doesn't check the divisor against 0 which allows you
to compute machine-specific representations of NaN and Inf by computing the results of 0/0 or 1/0
- New: Added IsNan(), IsInf(), and IsFinite() to math library to check a value against NaN, infinity, and
finiteness; also added the constants #NAN and #INF which contain the values of NaN and infinity; note
that due to the design of the parser, you cannot use #NAN as a literal value in your scripts; instead,
you have to use GetConstant("#NAN") to get the value of #NAN; #INF, on the other hand, can be used in
scripts; note: do not test for NaN by comparing the number with itself, expecting to get FALSE; this
won't work on all platforms; always use IsNan()
Re: NaN and Infinity
Posted: Mon Jul 22, 2019 6:00 pm
by Bugala
That was quick service. Was just about to ask if there be possibility to accept division by zero somehow, since that have been trouble so many times. Not really a big deal, since it is easy to fix, but slight annoyance every time.
Re: NaN and Infinity
Posted: Mon Jul 22, 2019 6:24 pm
by airsoftsoftwair
Bugala wrote: ↑Mon Jul 22, 2019 6:00 pm
That was quick service. Was just about to ask if there be possibility to accept division by zero somehow, since that have been trouble so many times.
What's so funny about dividing by zero? Because it is forbidden?

Re: NaN and Infinity
Posted: Fri Jul 26, 2019 12:31 am
by Clyde
Perfect, thanks a lot, Andreas!