You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add an #int subtype of #number, something along the lines of this solution, with a #dec subtype to complement it.
Question: Should / division of two #int numbers always result in a #number?
The div operator can provide integer division.
a: 15-- inferred as #intb: 4-- inferred as #inta/b--> #number 3.7515/3--> #number 5adivb--> #int 3
The mod and rem operators provide the modulo (floored) and remainder (truncated) of a division, respectively.
-5mod3--> #int 1-5rem3--> #int -2
Testing for an #int could be (in ECMAScript) typeof x === 'number' && x % 1 === 0, and converting to an #int would be simply Number.parseInt(x).
Arbitrary precision
#bigint should of course also be supported, as well as (eventually) #bigdec and (hopefully) #ratio.
Division of two #bigint numbers could result in a #ratio. #ratio must be a value type, so as a hack it could be implemented as a tuple of (@ratio, numerator, denominator).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Suggestion
Add an
#int
subtype of#number
, something along the lines of this solution, with a#dec
subtype to complement it.Question: Should
/
division of two#int
numbers always result in a#number
?The
div
operator can provide integer division.The
mod
andrem
operators provide the modulo (floored) and remainder (truncated) of a division, respectively.Testing for an
#int
could be (in ECMAScript)typeof x === 'number' && x % 1 === 0
, and converting to an#int
would be simplyNumber.parseInt(x)
.Arbitrary precision
#bigint
should of course also be supported, as well as (eventually)#bigdec
and (hopefully)#ratio
.Division of two
#bigint
numbers could result in a#ratio
.#ratio
must be a value type, so as a hack it could be implemented as a tuple of(@ratio, numerator, denominator)
.Possible numeric types
#number
#int
#dec
#bigint
#bigdec
#ratio
Beta Was this translation helpful? Give feedback.
All reactions