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

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

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

atof.c
/* Copyright (C) 1983 by Manx Software Systems */
#include	<ctype.h>

double
atof(cp)
register char *cp;
{
	double acc, zero = 0.0, ten = 10.0;
	int msign, esign, dpflg;
	int i, dexp;

	while (*cp == ' ' || *cp == '\t')
		++cp;
	if (*cp == '-') {
		++cp;
		msign = 1;
	} else {
		msign = 0;
		if (*cp == '+')
			++cp;
	}
	dpflg = dexp = 0;
	for (acc = zero ; ; ++cp) {
		if (isdigit(*cp)) {
			acc *= ten;
			acc += *cp - '0';
			if (dpflg)
				--dexp;
		} else if (*cp == '.') {
			if (dpflg)
				break;
			dpflg = 1;
		} else
			break;
	}
	if (*cp == 'e' || *cp == 'E') {
		++cp;
		if (*cp == '-') {
			++cp;
			esign = 1;
		} else {
			esign = 0;
			if (*cp == '+')
				++cp;
		}
		for ( i = 0 ; isdigit(*cp) ; i = i*10 + *cp++ - '0' )
			;
		if (esign)
			i = -i;
		dexp += i;
	}
	if (dexp < 0) {
		while (dexp++)
			acc /= ten;
	} else if (dexp > 0) {
		while (dexp--)
			acc *= ten;
	}
	if (msign)
		acc = -acc;
	return acc;
}

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

floor.c
#include	<math.h>

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

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

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

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

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

	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;
}

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


_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	_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

.c.r:
	c68 +b $*.c

.a68.r:
	as68 $*.a68

.c.r32:
	c68 +bl -o $@ $*.c

CREL=atof.r ftoa.r floor.r
CREL32=atof.r32 ftoa.r32 floor.r32
AREL=abs.r acos.r asin.r atan.r cos.r\
	cosh.r exp.r log.r log10.r lvo.r\
	math.r modf.r pow.r sin.r sincos.r\
	sinh.r sp.r sqrt.r tan.r tanh.r

all:	$(CREL) $(AREL) $(CREL32)

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

	public	amiga_math
amiga_math:
	tst.l	_MathTransBase
	bne	skip
	clr.l	-(sp)
	pea	libnam
	jsr	__OpenLibrary
	add.w	#8,sp
	move.l	d0,_MathTransBase
	tst.l	d0
	bne	skip
	move.w	#23,-(sp)
	pea	msg
	move.w	#2,-(sp)
	jsr	_write
	add.w	#8,sp
	move.w	#1,-(sp)
	jsr	_exit
skip
	move.l	_MathTransBase,a6
	add.w	(sp)+,a6
	move.l	4(sp),d0
	move.l	12(sp),d1
	jmp	(a6)

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

	public	_exit
	public	_write
	public	__OpenLibrary

	dseg
	public	_MathTransBase
	end
modf.a68
;:ts=8
;
;	modf(d, dptr)
;		returns fractional part of d, and
;		stores integral part into *dptr
;
	public	_MathBase
	public	_LVOSPFix
	public	_LVOSPFlt
	public	_LVOSPSub

	public	_modf
_modf
	move.l	4(sp),d0
	move.l	_MathBase,a6
	jsr	_LVOSPFix(a6)
	jsr	_LVOSPFlt(a6)
	move.l	12(sp),a0
	move.l	d0,(a0)+
	clr.l	(a0)
	move.l	4(sp),d1
	jmp	_LVOSPSub(a6)
;
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

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	_SPTieee
_SPTieee
	public	_SPFieee
_SPFieee
	move.l	4(sp),d0
	rts

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

