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

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

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

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

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

	public	_atan
_atan:
	move.l	#_LVOIEEEDPAtan#,a0
	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(double v, double u)
{
	double f;
	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#,a0
	jmp	amiga_ieee_trans#

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

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

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

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

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

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

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

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

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

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

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

	public	_log10
_log10:
	move.l	#_LVOIEEEDPLog10#,a0
	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
CC=qcc
AS=as
CFLAGS=
AFLAGS=
O=oss

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

CLIB=\
	atan2.$O random.$O
ALIB=\
	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

mlib:	$(CLIB) $(ALIB)

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

	public	_pow
_pow:
	move.l	#_LVOIEEEDPPow#,a0
	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.
 */

#include <math.h>

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) 1987 by Manx Software Systems, Inc.
; :ts=8

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

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

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

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

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

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

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

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

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

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

	public	__abort
	public	_SysBase
	public	_DOSBase
	public	_MathIeeeDoubTransBase

	public	amiga_ieee_trans
amiga_ieee_trans:
	tst.l	_MathIeeeDoubTransBase
	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,_MathIeeeDoubTransBase
	bne	done
	move.l	_DOSBase,a6
	jsr	-60(a6)		;Output
	move.l	d0,d1
	lea	msg,a0
	move.l	a0,d2
	move.l	#22,d3
	jsr	-48(a6)		;Write
	move.l	#1,-(sp)
	jsr	__abort
done
	movem.l	(sp)+,d0-d3/a0/a1/a6
skip
	move.l	a6,-(sp)
	move.l	_MathIeeeDoubTransBase,a6
	jsr	(a6,a0.l)
	move.l	(sp)+,a6
	rts

libnam	dc.b	'mathieeedoubtrans.library',0

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

