Hi Danilo,

Ah. I get it. Interesting idea. If you are going to use a list, could also
just put the 'scale' in a property of the list?

When I came across the 'allbase function in Mike Penchkin's code... I
thought of the following...
It would be a bit wasteful of storage, but could represent arbitrarily
sized fixed or floating point numbers in any base as a list, each list atom
being a digit in that base. If you keep the digits ordered (least...most)
significant,  the performance may be quite reasonable as well.

The arithmetic functions to manipulate those 'lists' would be an
interesting exercise in basic concepts... and with picolisp numbers, you
could work with not just bignums, but big number bases. For example..
simple positive addition, base10, might look something like this (code at
end)...

: (num2L 1234)
-> (4 3 2 1)
: (L2Num (num2L 1234))
-> "1234"
: (format (L2Num (num2L 1234)))
-> 1234
: (L+ (num2L 1234) (num2L 654321))
-> (5 5 5 5 5 6)
: (num2L (L+ (num2L 1234) (num2L 654321)))
-> (6 5 5 5 5 5)
: (format (L2Num (L+ (num2L 1234) (num2L 654321))))
-> 655555


/Lindsay

# TODO: Generalize Num2L, L2Num, or add similar functions to accept any
number base and scale.
(de num2L (N)
   (mapcar format (reverse (chop (format N))))
)

(de L2Num (L)
   (pack (reverse L))
)

# Positive number addition (the easiest one)
(de L+ (L1 L2)
   (let (R NIL  S 0  D 0  C 0)
      (default L1 '(0) L2 '(0))
      (if (> (length L2) (length L1)) (swap 'L1 (swap 'L2 L1)))
      (mapcar
         '((D1 D2)
            (setq S
               (+ (or D1 0) (or D2 0) C) )
            (until (< S 10)
               (setq S (- S 10))
               (inc 'C) )
            (setq R (cons S R)) )
         L1
         L2 )
      (if (> 0 C) (setq R (cons C R)))
      (reverse R)) )


On Mon, Feb 27, 2017 at 8:25 AM, Danilo Kordic <danilo.kor...@gmail.com>
wrote:

> By constructing base 10 floating point numbers with
> ``[list Significand 'E Exponent]''.
> As if `E' is a binary operator.  Of course that makes no sense in Lisp.
> ``(Decimal Significand Exponent)'' would make sense.
>
> For example:
>   : (sqrt 2)
>   -> (141421356237309505 E -17)
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>

Reply via email to