# .css-1lrpez4{margin-top:unset;}.css-1lrpez4:hover > span,.css-1lrpez4:focus-within > span{opacity:1;-webkit-transform:none;-ms-transform:none;transform:none;-webkit-transform-duration:0.1s;-ms-transform-duration:0.1s;transform-duration:0.1s;}The floating point package.css-14vda7h{font-size:15px;margin-inline-start:0.5rem;opacity:0;position:absolute;-webkit-transform:translateX(-4px);-ms-transform:translateX(-4px);transform:translateX(-4px);-webkit-transition:opacity 0.2s ease-out 0s,-webkit-transform 0.2s ease-out 0s;-webkit-transition:opacity 0.2s ease-out 0s,transform 0.2s ease-out 0s;transition:opacity 0.2s ease-out 0s,transform 0.2s ease-out 0s;}

Floating point numbers in the Z88 are stored as a 4-byte mantissa and a 1 byte exponent. The exponent byte is simply the exponent plus 127. The mantissa is a binary fraction in a standard form where the most significant bit is assumed 1 (ie. the number is greater than or equal to 0.5 and less than 1). This is analogous to a base 10 standard from where the mantissa is of the form 0.xyz... (the usual choice is x.yz... but this is a matter of human convention) - x cannot be zero, as if it were then the number would be represented with a mantissa of 0.yz... and the exponent incremented. Hence the most significant bit of the mantissa may be taken to be 1 when calculating its magnitude, and can actually store other information. It is used as the mantissa sign bit, where 1 means a negative number. For example the decimal number 13 is binary 1101 or 0.1101*10^100; this would be represented as a mantissa of 01010000.....0000 (32bits - note the zero msb for positive number) and an exponent of 10000011 (131 decimal).

An exponent of zero is taken to mean that the mantissa is an integer - this allows integers which will fit in four bytes to be manipulated differently, avoiding irritating features such as 10 becomming 9.999998, whilst retaining the ability to cope with the large ranges which come with the floating point representative.

Floating point numbers are conventionally stored with the least significant bit of the mantissa at the lowest address, and the exponent at the highest. However, since numbers are represented to and returned from the floating point package in registers, this convention may be flouted at the programmer's discretion.

As mentioned earlier, the floating point package (hereinafter referred to as the FPP) uses a different `RST` call from the main system calls, the format of a floating point call is as follows:

`Â Â Â Â Â Â Â Â Â Â Â  RSTÂ  \$18Â Â Â Â Â Â Â Â Â Â Â  DEFB <function code>`

so apart from the different restart number, much the same as the OS calls. In the Z80 assembler notation we use:

`Â Â Â Â Â Â Â Â Â Â Â  FPP <function symbol>`

Parameters are passed to and from the FPP in a rather bizarre collection of registers. The main register group is HLhlC (remember, lower case for alternate set), and where a second parameter is required it is passed in DEdeB. These divide into mantissa and exponent as follows:

`Param1Â Â Â Â Â  Param2Â Â Â Â Â  SignificanceHÂ Â Â Â Â Â Â Â Â Â  DÂ Â Â Â Â Â Â Â Â Â  Most significant byte of mantissaLÂ Â Â Â Â Â Â Â Â Â  EhÂ Â Â Â Â Â Â Â Â Â  dlÂ Â Â Â Â Â Â Â Â Â  eÂ Â Â Â Â Â Â Â Â Â  Least significant byte of mantissaCÂ Â Â Â Â Â Â Â Â Â  BÂ Â Â Â Â Â Â Â Â Â  Exponent byte`

There are certain exceptions, which are explained where relevant (for instance one operation returns the numeric value of a string, so takes a pointer to the string in HL as its parameter). Please refer to "System calls reference" for details of the specific function calls.Â
Â

## Example

The following is a simple example program, which prints out the mathematical constant PI. It makes two FPP calls, oneÂ FP_PIÂ to get the value, then aÂ FP_STRÂ to convert it to a string. This is then printed via the standardÂ GN_SopÂ routine.

Â

```include "stdio.def"Â Â  Â  Â Â  Â Â Â Â Â Â Â Â  ; standard I/O definitionsÂ
include "fpp.def" Â  Â Â  Â Â Â Â Â Â Â Â Â Â Â Â  ; floating point definitionsÂ

; routine assumes that IY points to small buffer on entryÂ
; buffer size at least 15 bytes

.print_piÂ Â  fpp  FP_PIÂ Â Â Â Â Â Â Â Â Â Â Â Â  ; get value of PI in HLhlC
Â Â Â Â Â Â Â Â Â Â Â  push iy
Â Â Â Â Â Â Â Â Â Â Â  popÂ  deÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  ; buffer address in DE
Â Â Â Â Â Â Â Â Â Â Â  exxÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  ; swap to alternate registers
Â Â Â Â Â Â Â Â Â Â Â  ldÂ Â  de, \$000AÂ Â Â Â Â Â Â Â Â  ; format control variable (10 digits)
Â Â Â Â Â Â Â Â Â Â Â  exx
Â Â Â Â Â Â Â Â Â Â Â  fpp  FP_STRÂ Â Â Â Â Â Â Â Â Â Â Â  ; convert number to ASCII string
Â Â Â Â Â Â Â Â Â Â Â  xorÂ  a
Â Â Â Â Â Â Â Â Â Â Â  ldÂ Â  (de),aÂ Â Â Â Â Â Â Â Â Â Â Â  ; null-terminate string
Â Â Â Â Â Â Â Â Â Â Â  push iy
Â Â Â Â Â Â Â Â Â Â Â  popÂ  hlÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  ; buffer address in HL
Â Â Â Â Â Â Â Â Â Â Â  oz   GN_Sop Â Â Â    Â Â Â Â Â  ; display number to standard output
Â Â Â Â Â Â Â Â Â Â Â  oz   GN_Nln    Â Â Â Â Â Â Â Â  ; newline
Â Â Â Â Â Â Â Â Â Â Â  retÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  ; finished (return to caller)
```