# Re: Questions

Hi Kriangkrai,

> Ah, Thanks. Could you please explain how a "double" value is encoded
> in "cell"? I could not "decipher" doubleToNum() and numToDouble() in
> big.c!

As PicoLisp only handles scaled fixed point numbers, the "double" is
encoded as a number, with the additional scale passed to the functions.
In general, a number is encoded in cells as

Number
|
V
+-----+-----+     +-----+-----+     +-----+-----+
|'DIG'|  ---+---> |'DIG'|  ---+---> |'DIG'|  /  |
+-----+-----+     +-----+-----+     +-----+-----+

where each digig 'DIG' holds 32 bits of information (in the 64 bit
version, there are also 60 bit short numbers, and the bignum cells
naturally hold 64 bits). The sign is in the lowest bit of the first
digit.

So what numToDouble() does is: Take that number, scale and add up all
the digits, and finally set the sign. doubleToNum() does the opposite,
by fitting a (sufficiently large) double number into the above cell
structure.

>    : *Scl
>    -> 0
>    : (let *Scl 2 1.23)
>    -> 1
> Is this because 1.23 is "parsed" when *Scl is still 0, right?

Correct. '*Scl' only applies to input (the "reader"). It is usually set
globally, at the beginning of an application, e.g. with (setq *Scl 2).
In general, it is not so very useful and important, as the I/O format
will always depend on the local context.

> Is there a better way than using:
>    : (let *Scl 2 (format "1.23" *Scl))

Probably not. Typically, such cases will not use the global '*Scl', but
some value from the database or some other context.

For example, the numeric input fields in "lib/form.l" each have their
own local scale. The other parameters to 'format' (the decimal and
thousands delimiter) are usually taken from the current locale.

> 1. What does 'mis>' stand for?

In the sense of negation (as in "misfit" or "misfortune"). This message
is sent to relation objects to check if a given value will fit. If not,
the GUI issues an error message. Most of these methods are defined in
"lib/db.l".

> 2. Why a "reverse" association list (instead of a normal association
> list) is used for the "property list"?
>    : (putl 'X '((10 . a) (20 . b))) (show 'X)

This has advantages if you access these cells directly, with 'prop'
or '::'. While

: (get 'X 'a)
-> 10

will give the value,

: (prop 'X 'a)
-> (10 . a)

returns the whole cell. This can be used with all functions that accept
a 'var' argument (a 'var' is either a symbol or a cell):

: (inc (prop 'X 'a))
-> 11
: (get 'X 'a)
-> 11