Proposed numeric type hierarchy
James Knight <[email protected]> Sat, 19 Oct 2002 15:51:44 -0400
| Newsgroups | gmane.comp.lang.goo.general |
|---|---|
| Message-ID | <[email protected]> |
So, a complete number type hierarchy for GOO with all the standard common-lispish types, plus quantities (numbers with a unit) looks something like the following (at the bottom). Unfortunately there's a lot of types here, and I'm really bad at coming up with short names (jrb maybe you can help out here..) This proposal changes the meaning of <num> pretty drastically (and makes it a lot less useful). A bunch of methods that used to take <num> should really be taking <real>, as they don't want to deal with numbers which are not magnitudes (complex numbers are not comparable with "<"). A bunch more methods that used to take <num> should really be taking <scalar> as they are able to deal with quantities just fine (this includes many of the math functions). So far, I've got <bignum> working, and a somewhat-working <qty> type (but it'll need more work). That leaves <complex>, <ratio>, and more precise (or arbitrarily big with the GMP mpf set of functions) floats. Introducing complex numbers will probably be the most difficult, because getting all the algorithms correct will take some work. Compilers/libraries that support C99 can do complex calculations on single and double floats though, so maybe that'll be good enough. Comments? James ---- type hierarchy ---- ;; I hope this is the right use of the term 'scalar' (dc <scalar> (<any>)) ;; scalars are either numbers (unitless) or quantities (composed ;; of a <num> and a unit) (dc <qty> (<scalar>)) (dc <num> (<scalar>)) ;; numbers are either real or complex. complex numbers are ;; composed of two <real>s. (dc <real> (<num> <mag>)) (dc <complex> (<num>)) ;; real numbers are either rational (and thus precisely representable), ;; or a floating point approximations of a (possibly irrational) number. (dc <rational> (<real>)) (dc <flo> (<real>)) ;; rational numbers are either integers or a ratio composed of two <int>s. (dc <int> (<rational>)) (dc <ratio> (<rational>)) ;; ints are either small or big, but most of the time users don't have to care. (dc <fixnum> (<int>)) (dc <bignum> (<int>)) ;; different precision floats. (dc <shortflo> (<flo>)) ;; 32bit (dc <longflo> (<flo>)) ;; 64bit (dc <arbitrary-precision-float-name> (<flo>))