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

Macros

#define MT_FUNC(code, name)

Functions

static ULONG codeinit (void)
 Library init - open mathtrans.library.
static void codefinit (struct Library *lib)
 Library finit - close mathtrans.library.
void dopow (void)
 The ^ operator for floats (the first nullsub, called by the compiler) - x^y with SPPow, the sign of a negative base kept.
void spacos (void)
 ACos, ASin, ATan, Cos, HCos, Exp, Log, Log10, Sin, HSin, Sqr, Tan, HTan (Float) - the mathtrans.library function named in the comment of each line.
void spasin (void)
void spatan (void)
void spcos (void)
void spcosh (void)
void spexp (void)
void splog10 (void)
void splog (void)
void spsin (void)
void spsinh (void)
void spsqrt (void)
void sptan (void)
void sptanh (void)
 MT_FUNC (spacos, "ACos")
 MT_FUNC (spasin, "ASin")
 MT_FUNC (spatan, "ATan")
 MT_FUNC (spcos, "Cos")
 MT_FUNC (spcosh, "HCos")
 MT_FUNC (spexp, "Exp")
 MT_FUNC (splog10, "Log10")
 MT_FUNC (splog, "Log")
 MT_FUNC (spsin, "Sin")
 MT_FUNC (spsinh, "HSin")
 MT_FUNC (spsqrt, "Sqr")
 MT_FUNC (sptan, "Tan")
 MT_FUNC (sptanh, "HTan")

Variables

static const char libname [] = "mathtrans.library"

Macro Definition Documentation

◆ MT_FUNC

#define MT_FUNC ( code,
name )
Value:
BLITZ_ARGS(BL_FLOAT); \
BLITZ_LIBS(LIB_mathtranslib, BL_LA6); \
BLITZ_SUBS(code, 0, 0); \
BLITZ_NAME(name, "(Float)")
char * name
Definition asllib.c:150
#define BLITZ_AFUNCTION(t)
Definition blitzlib.h:344
#define BL_LA6
Definition blitzlib.h:201
#define BL_FLOAT
Definition blitzlib.h:94
UBYTE code[4]
Definition ridisasmlib.c:375

Function Documentation

◆ codefinit()

void codefinit ( struct Library * lib)
static

Library finit - close mathtrans.library.

MOVE.l 4,a6:JMP _CloseLibrary(a6); Fixed (#202): only if the base is not 0 (with the init above it may be; CloseLibrary(0) crashes on Kickstart 1.x).

Parameters
liba1: the library base (!libs mathtranslib,la1).

◆ codeinit()

ULONG codeinit ( void )
static

Library init - open mathtrans.library.

OldOpenLibrary once: the base or 0.

Fixed (#202): the original tries again forever if the library cannot be opened (initloop: TST.l d0:BEQ initloop), so a program that uses a transcendental function hung at startup without LIBS:mathtrans.library. Now the program runs with base 0, as with a missing library of the deflibs (#44): a call of a function of mathtranslib then crashes (JSR to a negative offset from 0); a program that can do without them checks for the library itself first.

Returns
d0: the library base or 0, the init value (a6 of the functions).

◆ dopow()

void dopow ( void )

The ^ operator for floats (the first nullsub, called by the compiler) - x^y with SPPow, the sign of a negative base kept.

Fixed (#1189): the original is the inline JSR -90(a6) (SPPow), which gives |x|^y for a negative x, also for a whole odd exponent: (-2.5)^3 gave 15.625. Now a base that is not negative jumps to SPPow as before; a negative one is passed to SPPow as |x|, and the result is negative when y is a whole odd number: (-2.5)^3 is -15.625, (-2)^2 4, (-2)^-1 -0.5. A result 0 stays 0. With a fractional exponent there is no real power and the value stays |x|^y, as in the original (whether that becomes a runtime error is open in #1189).

Whole and odd from the FFP bits: the mantissa M in bits 31-8 (normalised), the sign in bit 7, the exponent in bits 6-0 (excess 64), the value M * 2^(e-24) with e = exponent - 64. e <= 0: 0 or below 1 in magnitude; e > 24: whole and even; otherwise y is a whole odd number if bit 24-e of M is set and the 24-e bits below it are 0 (e = 24: the value is M itself, 16777215 the largest odd one). LSL.l e of the mantissa (the low byte cleared) shifts bit 24-e of M into C and leaves the bits below it, the fraction: C set and the rest 0.

Assembler by nature: the tail jump into SPPow with the caller's registers (the inline call it replaces, the cost of the common case one test) and the bit test on the condition codes of the shift. The registers: those of the SPPow call (d0/d1/a0/a1 changed, a6 kept).

  • d0 x, the base (FFP).
  • d1 y, the exponent (FFP).
  • a6 the mathtrans.library base (!libs mathtranslib,la6).
    Result
    d0: x^y (FFP).

◆ MT_FUNC() [1/13]

MT_FUNC ( spacos ,
"ACos"  )

◆ MT_FUNC() [2/13]

MT_FUNC ( spasin ,
"ASin"  )

◆ MT_FUNC() [3/13]

MT_FUNC ( spatan ,
"ATan"  )

◆ MT_FUNC() [4/13]

MT_FUNC ( spcos ,
"Cos"  )

◆ MT_FUNC() [5/13]

MT_FUNC ( spcosh ,
"HCos"  )

◆ MT_FUNC() [6/13]

MT_FUNC ( spexp ,
"Exp"  )

◆ MT_FUNC() [7/13]

MT_FUNC ( splog ,
"Log"  )

◆ MT_FUNC() [8/13]

MT_FUNC ( splog10 ,
"Log10"  )

◆ MT_FUNC() [9/13]

MT_FUNC ( spsin ,
"Sin"  )

◆ MT_FUNC() [10/13]

MT_FUNC ( spsinh ,
"HSin"  )

◆ MT_FUNC() [11/13]

MT_FUNC ( spsqrt ,
"Sqr"  )

◆ MT_FUNC() [12/13]

MT_FUNC ( sptan ,
"Tan"  )

◆ MT_FUNC() [13/13]

MT_FUNC ( sptanh ,
"HTan"  )

◆ spacos()

void spacos ( void )

ACos, ASin, ATan, Cos, HCos, Exp, Log, Log10, Sin, HSin, Sqr, Tan, HTan (Float) - the mathtrans.library function named in the comment of each line.

Inline code (Dc $a000,len): the compiler copies the JSR lvo(a6) to the call; the original has no RTS behind it.

  • d0 the argument (FFP).
  • a6 the mathtrans.library base (!libs mathtranslib,la6).
    Result
    d0: the result (FFP).

◆ spasin()

void spasin ( void )

◆ spatan()

void spatan ( void )

◆ spcos()

void spcos ( void )

◆ spcosh()

void spcosh ( void )

◆ spexp()

void spexp ( void )

◆ splog()

void splog ( void )

◆ splog10()

void splog10 ( void )

◆ spsin()

void spsin ( void )

◆ spsinh()

void spsinh ( void )

◆ spsqrt()

void spsqrt ( void )

◆ sptan()

void sptan ( void )

◆ sptanh()

void sptanh ( void )

Variable Documentation

◆ libname

const char libname[] = "mathtrans.library"
static