I know that agent-js is able to accept Infinity and -Infinity and NaN values…how can these be represented in Candid text syntax form for values?
The spec doesn’t support inf/nan values in the textual format. Do you have a need to use inf/nan or just for completeness?
Interesting. I don’t really need it, but I wonder. If I have a BTree and I want to expose its search and keys are Nat.
With Nat64 I can do score.find(0, ^0, #fwd, 10);
But the ^0 of a Nat must be Infinity
^0 mean? The original question was about inf/nan for float type. There is no infinity for Nat by definition.
For a Nat64, it just the maximum Nat64 possible. For a Nat it has to be 0 to Infinity, if you want to scan the whole range.
Docs say Nat = Natural numbers with infinite precision.
Which must mean Nat can be Infinite ?
Yes, infinite precision means there is no fixed range. You cannot have infinite in Nat.
I thought I had replied to this. I was just doing property tests and we can across some issues with Infinity and NaN, and I went to manually test these issues with dfx and realized that I didn’t know how…so it’s a little strange that the agent-js can handle NaN and Infinity but Candid itself can’t.
So for completeness I guess
I agree. I add a tracking issue: Support parsing inf/nan for float type · Issue #499 · dfinity/candid · GitHub. Candid itself can handle inf/nan in binary form, it’s just the textual parser that couldn’t handle it. I think in Motoko, we also cannot specify inf/nan.