BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
floatquicklib.c File Reference
#include "blitzlib.h"

Macros

#define f65536   0x80000051 /* 65536.0 in FFP */

Functions

void quicktofloat (void)
 $D300 qutofl: convert a Quick (16.16 fixed point) to a Float (FFP).
void floattoquick (void)
 $D301 fltoqu: convert a Float (FFP) to a Quick (16.16 fixed point).

Macro Definition Documentation

◆ f65536

#define f65536   0x80000051 /* 65536.0 in FFP */

Function Documentation

◆ floattoquick()

void floattoquick ( void )

$D301 fltoqu: convert a Float (FFP) to a Quick (16.16 fixed point).

BCHG #7,d0:BEQ 'doit:BSR 'doit2:NEG.l d0:RTS / 'doit:BCHG #7,d0 ('doit2): converts the magnitude (SPFix(x) << 16 | SPFix((x - int) * 65536.0), by mathffp) and negates it if the sign bit was set.

  • d0 f, the Float
  • a6 ffpbase, mathffp.library (ffplib)
    Result
    d0: the Quick; d1 changed, a0/a1 (third party: RIMiscLib) and d2-d7/a2-a6 kept

◆ quicktofloat()

void quicktofloat ( void )

$D300 qutofl: convert a Quick (16.16 fixed point) to a Float (FFP).

The sign is tested on d0 (TST.l d0:BPL 'doit2); negative inputs are converted as their magnitude (float(int part) + float(frac) / 65536.0, by mathffp; the magnitude of $80000000 is 32768.0, read as unsigned) and get the FFP sign bit (bit 7) set. Fixed (#146, #147): the original tests the sign on -d0 (NEG.l d0:BMI 'doit:BSR 'doit2:BSET #7,d0:RTS / 'doit:NEG.l d0): 0 counted as negative (NEG gives 0, not minus), so Quick 0 became $00000080, an FFP "-0" (#146); NEG of $80000000 overflows and stays negative, so -32768.0 became +32768.0 (#147). The test on d0 costs no more than the original's (one TST.l instead of the NEG.l of a copy).

  • d0 q, the Quick
  • a6 ffpbase, mathffp.library (ffplib)
    Result
    d0: the Float; d1 changed, a0/a1 and d2-d7/a2-a6 kept