[Nickle]Numeric type heirarchy
Keith Packard
keithp@keithp.com
Fri, 23 Feb 2001 09:58:24 -0800
Nickle currently incorporates several internal numeric representations and
exposes several numeric datatypes. While these use the same names, the
language groups several representations together as a single datatype.
In the implementation, there are:
type_int 32 bit integer
type_integer arbitrary precision natural + sign
type_rational two naturals + sign
type_double C 'double'.
In the language, there are:
int type_int
integer type_int or type_integer
rational type_int, type_integer or type_rational
double type_int, type_integer, type_rational or type_double
I think I should remove 32-bit integers from the language; they're not
useful.
I'm about to add a 'type_float' which uses a natural mantissa, natural
exponent two signs and a 32-bit integer indicating the number of bits in
the mantissa. This will eliminate the inability to convert large or small
values into an imprecise representation.
Once this new representation is available, I'd like to change the
internal names to:
type_int natural + sign
type_ratio two naturals + sign
type_float two naturals, two signs and a 32-bit precision
The language datatypes become:
integer type_int
rational type_ratio or type_int
real type_float, type_ratio or type_int
As for datatype conversions:
real imprecise (real value, integer bits)
Convert 'value' to an imprecise repsentation using no more than
'bits' bits.
integer floor (real value)
integer ceil (real value)
integer round (real value)
Convert 'value' to the nearest integer in the indicated direction.
Is there any conventional function name for converting an imprecise number
into a nearby rational approximation? Certainly it's easy to do:
rational function nearby (real value, integer denom) {
return round (value * denom) / denom;
}
-keith