rhaiscript / rhai

Rhai - An embedded scripting language for Rust.
https://crates.io/crates/rhai
Apache License 2.0
3.82k stars 180 forks source link

How to write Infinity #534

Closed Kaiser1989 closed 2 years ago

Kaiser1989 commented 2 years ago

I searched docs and code but didn't find anything.

Is it possible to write Infinity as number? Currently i'm only able to do it by this math statement:

print(1.0 / 0.0)

outputs

Waiting for Web Worker to finish loading...
Running script at 2022-03-07T11:15:04.027Z

[PRINT] inf

Script returned: ""
Finished at 2022-03-07T11:15:04.031Z
schungx commented 2 years ago

Well, I wonder why you'd want to...

But you can easily register a function, say inf(), that simply returns infinity.

While you're at it, you may want to distinguish between positive vs negative infinity.

Kaiser1989 commented 2 years ago

Inf, -Inf & NaN...

Maybe someone wants to check against NaN values. Just wondering if there are any build-in functions.

I will register them myself. THX for your fast answer!

schungx commented 2 years ago

If you just want to test them, there are these functions: https://rhai.rs/book/language/num-fn.html#floating-point-functions

is_nan, is_finite, is_infinite