abs.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	.Fabs
	public	_fabs
_fabs
	move.l	4(sp),d0
	jmp	.Fabs

acos.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	amiga_math
	public	_LVOSPAcos
	public	_acos
_acos
	move.w	#_LVOSPAcos,-(sp)
	jmp	amiga_math

asin.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	amiga_math
	public	_LVOSPAsin
	public	_asin
_asin
	move.w	#_LVOSPAsin,-(sp)
	jmp	amiga_math

atan.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	amiga_math
	public	_LVOSPAtan
	public	_atan
_atan
	move.w	#_LVOSPAtan,-(sp)
	jmp	amiga_math

cos.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	amiga_math
	public	_LVOSPCos
	public	_cos
_cos
	move.w	#_LVOSPCos,-(sp)
	jmp	amiga_math

cosh.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	amiga_math
	public	_LVOSPCosh
	public	_cosh
_cosh
	move.w	#_LVOSPCosh,-(sp)
	jmp	amiga_math

exp.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	amiga_math
	public	_LVOSPExp
	public	_exp
_exp
	move.w	#_LVOSPExp,-(sp)
	jmp	amiga_math

fabs.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	.Fabs
	public	_fabs
_fabs
	move.l	4(sp),d0
	jmp	.Fabs

fadd.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	.Fadd
.Fadd:
	move.l	#_LVOSPAdd#,-(sp)
	jmp	amiga_ffp#

fcmp.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	.Fcmp
.Fcmp:
	move.l	#_LVOSPCmp#,-(sp)
	jmp	amiga_ffp#

fdiv.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	.Fdiv
.Fdiv:
	move.l	#_LVOSPDiv#,-(sp)
	jmp	amiga_ffp#

ffix.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	.Ffix
.Ffix:
	move.l	#_LVOSPFix#,-(sp)
	jmp	amiga_ffp#

fflt.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	.Fflt
.Fflt:
	move.l	#_LVOSPFlt#,-(sp)
	jmp	amiga_ffp#

ffp.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	__abort
	public	_SysBase
	public	_DOSBase
	public	_MathBase

	public	amiga_ffp
amiga_ffp:
	tst.l	_MathBase
	bne	skip
	movem.l	d0-d3/a0/a1/a6,-(sp)
	move.l	_SysBase,a6
	move.l	#0,d0
	lea	libnam,a1
	jsr	-552(a6)	;OpenLibrary
	move.l	d0,_MathBase
	bne	done
	move.l	_DOSBase,a6
	jsr	-60(a6)		;Output
	move.l	d0,d1
	lea	msg,a0
	move.l	a0,d2
	move.l	#16,d3
	jsr	-48(a6)		;Write
	move.l	#1,-(sp)
	jsr	__abort
done
	movem.l	(sp)+,d0-d3/a0/a1/a6
skip
	movem.l	d1/a0,-(sp)
	move.l	8(sp),a0
	move.l	a6,8(sp)
	move.l	_MathBase,a6
	jsr	(a6,a0.l)
	movem.l	(sp)+,d1/a0/a6
	rts

libnam	dc.b	'mathffp.library',0

msg	dc.b	'no math library',$a
ffpabs.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	.Fabs
.Fabs:
	move.l	#_LVOSPAbs#,-(sp)
	jmp	amiga_ffp#

floor.c
#include	<math.h>

double
floor(double d)
{
	if (d < 0.0)
		return -ceil(-d);
	modf(d, &d);
	return d;
}

double
ceil(double d)
{
	if (d < 0.0)
		return -floor(-d);
	if (modf(d, &d) > 0.0)
		++d;
	return d;
}

fmul.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	.Fmul
.Fmul:
	move.l	#_LVOSPMul#,-(sp)
	jmp	amiga_ffp#

fneg.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	.Fneg
.Fneg:
	move.l	#_LVOSPNeg#,-(sp)
	jmp	amiga_ffp#

fsub.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	.Fsub
.Fsub:
	move.l	#_LVOSPSub#,-(sp)
	jmp	amiga_ffp#

ftoa.c
/* Copyright (C) 1984 by Manx Software Systems, Inc. */

static long lround[] = {
	0xa0000044L,
	0x80000041L,
	0x80000040L,
	0xcccccd3cL,
	0xa3d70a39L,
	0x83126e36L,
	0xd1b71632L,
	0xa7c5ab2fL,
	0x8637bc2cL,
	0xd6bf9328L,
	0xabcc7625L,
	0x89705e22L,
	0xdbe6fd1eL,
	0xafebfe1bL,
	0x8cbccb18L,
	0xe12e1214L,
	0xb424db11L,
	0x901d7c0eL,
};

void
ftoa(double number, char *buffer, int maxwidth, int flag)
{
	register int i;
	int exp, digit, decpos, ndig;
	register float *round;

	round = (float *)lround;
	ndig = maxwidth+1;
	exp = 0;
	if (number < 0.0) {
		number = -number;
		*buffer++ = '-';
	}
	if (number > 0.0) {
		while (number < round[1]) {
			number *= round[0];
			--exp;
		}
		while (number >= round[0]) {
			number /= round[0];
			++exp;
		}
	}

	if (flag == 2) {		/* 'g' format */
		ndig = maxwidth;
		if (exp < -4 || exp >= maxwidth)
			flag = 0;		/* switch to 'e' format */
	} else if (flag == 1)	/* 'f' format */
		ndig += exp;

	if (ndig >= 0) {
		if ((number += round[(ndig>16?16:ndig)+1]) >= round[0]) {
			number = round[1];
			++exp;
			if (flag)
				++ndig;
		}
	}

	if (flag) {
		if (exp < 0) {
			*buffer++ = '0';
			*buffer++ = '.';
			i = -exp - 1;
			if (ndig <= 0)
				i = maxwidth;
			while (i--)
				*buffer++ = '0';
			decpos = 0;
		} else {
			decpos = exp+1;
		}
	} else {
		decpos = 1;
	}

	if (ndig > 0) {
		for (i = 0 ; ; ++i) {
			if (i < 16) {
				digit = (int)number;
				*buffer++ = digit+'0';
				number = (number - digit) * round[0];
			} else
				*buffer++ = '0';
			if (--ndig == 0)
				break;
			if (decpos && --decpos == 0)
				*buffer++ = '.';
		}
	}

	if (!flag) {
		*buffer++ = 'e';
		if (exp < 0) {
			exp = -exp;
			*buffer++ = '-';
		} else
			*buffer++ = '+';
		if (exp >= 100) {
			*buffer++ = exp/100 + '0';
			exp %= 100;
		}
		*buffer++ = exp/10 + '0';
		*buffer++ = exp%10 + '0';
	}
	*buffer = 0;
}

ftst.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	.Ftst
.Ftst:
	move.l	#_LVOSPTst#,-(sp)
	jmp	amiga_ffp#

log.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	amiga_math
	public	_LVOSPLog
	public	_log
_log
	move.w	#_LVOSPLog,-(sp)
	jmp	amiga_math

log10.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	amiga_math
	public	_LVOSPLog10
	public	_log10
_log10
	move.w	#_LVOSPLog10,-(sp)
	jmp	amiga_math

lvo.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8


_LVOSPCeil	equ	-96
_LVOSPFloor	equ	-90
_LVOSPDiv	equ	-84
_LVOSPMul	equ	-78
_LVOSPSub	equ	-72
_LVOSPAdd	equ	-66
_LVOSPNeg	equ	-60
_LVOSPAbs	equ	-54
_LVOSPTst	equ	-48
_LVOSPCmp	equ	-42
_LVOSPFlt	equ	-36
_LVOSPFix	equ	-30

	public	_LVOSPCeil
	public	_LVOSPFloor
	public	_LVOSPDiv
	public	_LVOSPMul
	public	_LVOSPSub
	public	_LVOSPAdd
	public	_LVOSPNeg
	public	_LVOSPAbs
	public	_LVOSPTst
	public	_LVOSPCmp
	public	_LVOSPFlt
	public	_LVOSPFix

_LVOSPLog10	equ	-126
_LVOSPAcos	equ	-120
_LVOSPAsin	equ	-114
_LVOSPFieee	equ	-108
_LVOSPTieee	equ	-102
_LVOSPSqrt	equ	-96
_LVOSPPow	equ	-90
_LVOSPLog	equ	-84
_LVOSPExp	equ	-78
_LVOSPTanh	equ	-72
_LVOSPCosh	equ	-66
_LVOSPSinh	equ	-60
_LVOSPSincos	equ	-54
_LVOSPTan	equ	-48
_LVOSPCos	equ	-42
_LVOSPSin	equ	-36
_LVOSPAtan	equ	-30

	public	_LVOSPLog10
	public	_LVOSPAcos
	public	_LVOSPAsin
	public	_LVOSPFieee
	public	_LVOSPTieee
	public	_LVOSPSqrt
	public	_LVOSPPow
	public	_LVOSPLog
	public	_LVOSPExp
	public	_LVOSPTanh
	public	_LVOSPCosh
	public	_LVOSPSinh
	public	_LVOSPSincos
	public	_LVOSPTan
	public	_LVOSPCos
	public	_LVOSPSin
	public	_LVOSPAtan

makefile
CC=qcc
AS=as
CFLAGS=
AFLAGS=
O=oss

.c.$O:
	$(CC) -o $@ $(CFLAGS) $*.c
.a68.$O:
	$(AS) -o $@ $(AFLAGS) $*.a68

MLIB=\
	floor.$O random.$O \
	acos.$O asin.$O atan.$O cos.$O \
	cosh.$O exp.$O fabs.$O fadd.$O fcmp.$O \
	fdiv.$O ffix.$O fflt.$O ffp.$O ffpabs.$O \
	fmul.$O fneg.$O fsub.$O ftst.$O log.$O \
	log10.$O lvo.$O math.$O modf.$O pow.$O \
	sin.$O sincos.$O sinh.$O sp.$O sqrt.$O \
	tan.$O tanh.$O tran.$O

mlib:	$(MLIB)

math.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	_MathTransBase
	public	_SysBase
	public	_DOSBase
	public	__abort

	public	amiga_math
amiga_math:
	tst.l	_MathTransBase
	bne	skip
	movem.l	d0-d3/a0/a1/a6,-(sp)
	move.l	_SysBase,a6
	move.l	#0,d0
	lea	libnam,a1
	jsr	-552(a6)	;OpenLibrary
	move.l	d0,_MathTransBase
	bne	done
	move.l	_DOSBase,a6
	jsr	-60(a6)		;Output
	move.l	d0,d1
	lea	msg,a0
	move.l	a0,d2
	move.l	#23,d3
	jsr	-48(a6)		;Write
	move.l	#1,-(sp)
	jsr	__abort
done
	movem.l	(sp)+,d0-d3/a0/a1/a6
skip
	move.w	(sp)+,a0
	move.l	4(sp),d0
	move.l	12(sp),d1
	move.l	a6,-(sp)
	move.l	_MathTransBase,a6
	jsr	(a6,a0)
	move.l	(sp)+,a6
	rts

libnam	dc.b	109,97,116,104,116,114,97,110,115,46,108,105,98,114,97
	dc.b	114,121,0

msg	dc.b	78,111,32,77,97,116,104,84,114,97,110,115
	dc.b	32,76,105,98,114,97,114,121,33,33,10,0

	end
modf.a68
;:ts=8
;
;	modf(d, dptr)
;		returns fractional part of d, and
;		stores integral part into *dptr
;
	public	.Ffix
	public	.Fflt
	public	.Fsub

	public	_modf
_modf
	move.l	4(sp),d0
	jsr	.Ffix
	jsr	.Fflt
	move.l	12(sp),a0
	move.l	d0,(a0)+
	clr.l	(a0)
	move.l	d0,d1
	move.l	4(sp),d0
	jmp	.Fsub
;
pow.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	amiga_math
	public	_LVOSPPow
	public	_pow
_pow
	move.w	#_LVOSPPow,-(sp)
	jmp	amiga_math

random.c
/*
 * Random number generator -
 * adapted from the FORTRAN version 
 * in "Software Manual for the Elementary Functions"
 * by W.J. Cody, Jr and William Waite.
 */

double exp(double), ran(void);

static long int iy = 100001;

void
sran(long seed)
{
	iy = seed;
}

double
ran(void)
{
	iy *= 125;
	iy -= (iy/2796203) * 2796203;
	return (double) iy/ 2796203.0;
}

double
randl(double x)
{

	return exp(x*ran());
}

sin.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	amiga_math
	public	_LVOSPSin
	public	_sin
_sin
	move.w	#_LVOSPSin,-(sp)
	jmp	amiga_math

sincos.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	amiga_math
	public	_LVOSPSincos
	public	_sincos
_sincos
	move.l	(sp)+,4(sp)
	jsr	sub
	move.l	8(sp),a0
	move.l	d1,(a0)
	move.l	4(sp),a0
	jmp	(a0)
sub
	move.w	#_LVOSPSincos,-(sp)
	jmp	amiga_math

sinh.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	amiga_math
	public	_LVOSPSinh
	public	_sinh
_sinh
	move.w	#_LVOSPSinh,-(sp)
	jmp	amiga_math

sp.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	_MathBase

	public	_LVOSPFix
	public	_SPFix
_SPFix
	move.l	4(sp),d0
	move.l	_MathBase,a6
	jmp	_LVOSPFix(a6)

	public	_LVOSPFlt
	public	_SPFlt
_SPFlt
	move.l	4(sp),d0
	move.l	_MathBase,a6
	jmp	_LVOSPFlt(a6)

	public	_LVOSPCmp
	public	_SPCmp
_SPCmp
	movem.l	4(sp),d0/d1
	exg	d0,d1
	move.l	_MathBase,a6
	jmp	_LVOSPCmp(a6)

	public	_LVOSPTst
	public	_SPTst
_SPTst
	move.l	4(sp),d1
	move.l	_MathBase,a6
	jmp	_LVOSPTst(a6)

	public	_LVOSPAbs
	public	_SPAbs
_SPAbs
	move.l	4(sp),d0
	move.l	_MathBase,a6
	jmp	_LVOSPAbs(a6)

	public	_LVOSPNeg
	public	_SPNeg
_SPNeg
	move.l	4(sp),d0
	move.l	_MathBase,a6
	jmp	_LVOSPNeg(a6)

	public	_LVOSPAdd
	public	_SPAdd
_SPAdd
	movem.l	4(sp),d0/d1
	move.l	_MathBase,a6
	jmp	_LVOSPAdd(a6)

	public	_LVOSPSub
	public	_SPSub
_SPSub
	movem.l	4(sp),d0/d1
	exg	d0,d1
	move.l	_MathBase,a6
	jmp	_LVOSPSub(a6)

	public	_LVOSPMul
	public	_SPMul
_SPMul
	movem.l	4(sp),d0/d1
	move.l	_MathBase,a6
	jmp	_LVOSPMul(a6)

	public	_LVOSPDiv
	public	_SPDiv
_SPDiv
	movem.l	4(sp),d0/d1
	exg	d0,d1
	move.l	_MathBase,a6
	jmp	_LVOSPDiv(a6)

	public	_LVOSPCeil
	public	_SPCeil
_SPCeil
	move.l	4(sp),d0
	move.l	_MathBase,a6
	jmp	_LVOSPCeil(a6)

	public	_LVOSPFloor
	public	_SPFloor
_SPFloor
	move.l	4(sp),d0
	move.l	_MathBase,a6
	jmp	_LVOSPFloor(a6)

sqrt.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	amiga_math
	public	_LVOSPSqrt
	public	_sqrt
_sqrt
	move.w	#_LVOSPSqrt,-(sp)
	jmp	amiga_math

tan.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	amiga_math
	public	_LVOSPTan
	public	_tan
_tan
	move.w	#_LVOSPTan,-(sp)
	jmp	amiga_math

tanh.a68
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8

	public	amiga_math
	public	_LVOSPTanh
	public	_tanh
_tanh
	move.w	#_LVOSPTanh,-(sp)
	jmp	amiga_math

tran.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	_MathTransBase

	public	_LVOSPAtan
	public	_SPAtan
_SPAtan
	move.l	4(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPAtan(a6)

	public	_LVOSPSin
	public	_SPSin
_SPSin
	move.l	4(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPSin(a6)

	public	_LVOSPCos
	public	_SPCos
_SPCos
	move.l	4(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPCos(a6)

	public	_LVOSPTan
	public	_SPTan
_SPTan
	move.l	4(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPTan(a6)

	public	_LVOSPSincos
	public	_SPSincos
_SPSincos
	move.l	4(sp),d1
	move.l	8(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPSincos(a6)

	public	_LVOSPSinh
	public	_SPSinh
_SPSinh
	move.l	4(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPSinh(a6)

	public	_LVOSPCosh
	public	_SPCosh
_SPCosh
	move.l	4(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPCosh(a6)

	public	_LVOSPTanh
	public	_SPTanh
_SPTanh
	move.l	4(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPTanh(a6)

	public	_LVOSPExp
	public	_SPExp
_SPExp
	move.l	4(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPExp(a6)

	public	_LVOSPLog
	public	_SPLog
_SPLog
	move.l	4(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPLog(a6)

	public	_LVOSPPow
	public	_SPPow
_SPPow
	move.l	4(sp),d1
	move.l	8(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPPow(a6)

	public	_LVOSPSqrt
	public	_SPSqrt
_SPSqrt
	move.l	4(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPSqrt(a6)

	public	_LVOSPTieee
	public	_SPTieee
_SPTieee
	move.l	4(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPTieee(a6)

	public	_LVOSPFieee
	public	_SPFieee
_SPFieee
	move.l	4(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPFieee(a6)

	public	_LVOSPAsin
	public	_SPAsin
_SPAsin
	move.l	4(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPAsin(a6)

	public	_LVOSPAcos
	public	_SPAcos
_SPAcos
	move.l	4(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPAcos(a6)

	public	_LVOSPLog10
	public	_SPLog10
_SPLog10
	move.l	4(sp),d0
	move.l	_MathTransBase,a6
	jmp	_LVOSPLog10(a6)

