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

	public	_acos
_acos:
	move.l	#_LVOIEEEDPAcos#,a6
	jmp	amiga_ieee_trans#

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

	public	_asin
_asin:
	move.l	#_LVOIEEEDPAsin#,a6
	jmp	amiga_ieee_trans#

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

	public	_atan
_atan:
	move.l	#_LVOIEEEDPAtan#,a6
	jmp	amiga_ieee_trans#

atan2.c
#include "math.h"
#include "errno.h"

#ifdef MPU8086
#define MAXEXP	1024
#define MINEXP	-1023
#else
#define MAXEXP	504
#define MINEXP	-512
#endif

#define PI		3.14159265358979323846
#define PIov2	1.57079632679489661923

double atan2(v,u)
double u,v;
{
	double f, frexp();
	int vexp, uexp;
	extern int flterr;
	extern int errno;

	if (u == 0.0) {
		if (v == 0.0) {
			errno = EDOM;
			return 0.0;
		} else if (v > 0.0 )
			return PIov2;
		return -PIov2;
	}

	frexp(v, &vexp);
	frexp(u, &uexp);
	if (vexp-uexp > MAXEXP-3)	/* overflow */
		f = PIov2;
	else {
		if (vexp-uexp < MINEXP+3)	/* underflow */
			f = 0.0;
		else
			f = atan(fabs(v/u));
		if (u < 0.0)
			f = PI - f;
	}
	if (v < 0.0)
		f = -f;
	return f;
}

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

	public	_cos
_cos:
	move.l	#_LVOIEEEDPCos#,a6
	jmp	amiga_ieee_trans#

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

	public	_cosh
_cosh:
	move.l	#_LVOIEEEDPCosh#,a6
	jmp	amiga_ieee_trans#

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

		public	.dtof
.dtof:
	movem.l	a0/a1/a6,-(sp)
	movem.l	d0/d1,-(sp)
	move.l	#_LVOIEEEDPTieee#,a6
	jsr	amiga_ieee_trans#
	add.w	#8,sp
	movem.l	(sp)+,a0/a1/a6
	rts

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

	public	_exp
_exp:
	move.l	#_LVOIEEEDPExp#,a6
	jmp	amiga_ieee_trans#

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

		public	.ftod
.ftod:
	movem.l	a0/a1/a6,-(sp)
	move.l	d0,-(sp)
	move.l	#_LVOIEEEDPFieee#,a6
	jsr	amiga_ieee_trans#
	add.w	#4,sp
	movem.l	(sp)+,a0/a1/a6
	rts

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

	public	_log
_log:
	move.l	#_LVOIEEEDPLog#,a6
	jmp	amiga_ieee_trans#

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

	public	_log10
_log10:
	move.l	#_LVOIEEEDPLog10#,a6
	jmp	amiga_ieee_trans#

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

_LVOIEEEDPAtan		equ	-30
_LVOIEEEDPSin		equ	-36
_LVOIEEEDPCos		equ	-42
_LVOIEEEDPTan		equ	-48
_LVOIEEEDPSincos	equ	-54
_LVOIEEEDPSinh		equ	-60
_LVOIEEEDPCosh		equ	-66
_LVOIEEEDPTanh		equ	-72
_LVOIEEEDPExp		equ	-78
_LVOIEEEDPLog		equ	-84
_LVOIEEEDPPow		equ	-90
_LVOIEEEDPSqrt		equ	-96
_LVOIEEEDPTieee		equ	-102
_LVOIEEEDPFieee		equ	-108
_LVOIEEEDPAsin		equ	-114
_LVOIEEEDPAcos		equ	-120
_LVOIEEEDPLog10		equ	-126

	public	_LVOIEEEDPAtan
	public	_LVOIEEEDPSin
	public	_LVOIEEEDPCos
	public	_LVOIEEEDPTan
	public	_LVOIEEEDPSincos
	public	_LVOIEEEDPSinh
	public	_LVOIEEEDPCosh
	public	_LVOIEEEDPTanh
	public	_LVOIEEEDPExp
	public	_LVOIEEEDPLog
	public	_LVOIEEEDPPow
	public	_LVOIEEEDPSqrt
	public	_LVOIEEEDPTieee
	public	_LVOIEEEDPFieee
	public	_LVOIEEEDPAsin
	public	_LVOIEEEDPAcos
	public	_LVOIEEEDPLog10

makefile
.c.o:
	cc +bfi +x3 -o $@ $*.c
.c.l:
	cc +bcdfi +x3 -o $@ $*.c

.a68.o:
	as -o $@ $*.a68
.a68.l:
	as -cdo $@ $*.a68

C=atan2.o random.o
ASM=acos.o asin.o atan.o cos.o cosh.o\
	dtof.o exp.o ftod.o log.o log10.o\
	lvo.o pow.o sin.o sinh.o sqrt.o\
	tan.o tanh.o trans.o
LC=atan2.l random.l
LASM=acos.l asin.l atan.l cos.l cosh.l\
	dtof.l exp.l ftod.l log.l log10.l\
	lvo.l pow.l sin.l sinh.l sqrt.l\
	tan.l tanh.l trans.l

all:	16 l16

16:		$(C) $(ASM)

l16:	$(LC) $(LASM)

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

	public	_pow
_pow:
	move.l	#_LVOIEEEDPPow#,a6
	movem.l	12(sp),d2/d3
	jmp	amiga_ieee_trans#

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.
 */

static long int iy = 100001;

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

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

double randl(x)
double x;
{
	double exp();

	return exp(x*ran());
}

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

	public	_sin
_sin:
	move.l	#_LVOIEEEDPSin#,a6
	jmp	amiga_ieee_trans#

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

	public	_sinh
_sinh:
	move.l	#_LVOIEEEDPSinh#,a6
	jmp	amiga_ieee_trans#

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

	public	_sqrt
_sqrt:
	move.l	#_LVOIEEEDPSqrt#,a6
	jmp	amiga_ieee_trans#

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

	public	_tan
_tan:
	move.l	#_LVOIEEEDPTan#,a6
	jmp	amiga_ieee_trans#

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

	public	_tanh
_tanh:
	move.l	#_LVOIEEEDPTanh#,a6
	jmp	amiga_ieee_trans#

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

	public	__abort
	public	__Write
	public	__Output
	public	__OpenLibrary
	public	_MathIeeeDoubTransBase

	public	amiga_ieee_trans
amiga_ieee_trans:
	tst.l	_MathIeeeDoubTransBase
	bne	skip
	movem.l	d0/d1/a0/a1/a6,-(sp)
	clr.l	-(sp)
	pea	libnam
	jsr	__OpenLibrary
	add.w	#8,sp
	move.l	d0,_MathIeeeDoubTransBase
	bne	done
	move.l	#22,-(sp)
	pea	msg
	jsr	__Output
	move.l	d0,-(sp)
	jsr	__Write
	move.l	#1,(sp)
	jsr	__abort
done
	movem.l	(sp)+,d0/d1/a0/a1/a6
skip
	movem.l	4(sp),d0/d1
	move.l	a6,a0
	move.l	_MathIeeeDoubTransBase,a6
	jmp	(a6,a0.l)

libnam	dc.b	'mathieeedoubtrans.library',0

msg	dc.b	'no ieee trans library',$a

