
* Maxon C++
* Library "math_conv"
* Jens Gelhar (Himpelsoft) 19.03.93, 15.04.94, 06.09.94

	xdef	lib_double2float,lib_float2double

lib_double2float:	; d0||d1 nach d0
	tst.l	d0
	beq.b	dtfRet
	move.l	d2,-(a7)
	move.l	d0,d2
	bclr	#31,d2
	tst.l	d2
	beq.b	dtf0		; Null bleibt Null
	clr.w	d2
	swap	d2
	lsr.w	#4,d2
	and.w	#$7FF,d2	; Exponent
	sub.w	#$3FF,d2
	cmp.w	#$80,d2
	bgt.b	dtf4		; Überlauf
	cmp.w	#-$7F,d2
	blt.b	dtf0		; Unterlauf
	add.w	#$7F,d2		; richtiger Exponent
	tst.l	d0
	bpl.b	dtf1
	bset	#8,d2		; Vorzeichen setzen
dtf1	and.l	#$FFFFF,d0	; Mantisse ausmaskieren
	; 3 Bits aus d1 in die Mantisse shiften:
	asl.l	#1,d1
	roxl.l	#1,d0
	asl.l	#1,d1
	roxl.l	#1,d0
	asl.l	#1,d1
	roxl.l	#1,d0
	swap	d2
	asl.l	#7,d2
	or.l	d2,d0
	move.l	(a7)+,d2
	rts
dtf4	; Überlauf:
	move.l	(a7)+,d2
	or.l	#$7FFFFFFF,d0
	rts
dtf0	; Unterlauf bzw. Null:
	moveq	#0,d0
	move.l	(a7)+,d2
dtfRet	rts

	SECTION "Code2",CODE

lib_float2double:	; d0 nach d0||d1
	tst.l d0
	beq.b ftdNull
	move.l d2,-(a7)
	move.l d0,d2
	and.l #$7FFFFF,d0       ; Short-Mantisse ausmaskieren
	moveq #0,d1
	lsr.l #1,d0             ; 3 Bits verschieben
	roxr.l #1,d1
	lsr.l #1,d0
	roxr.l #1,d1
	lsr.l #1,d0
	roxr.l #1,d1
	; Vorzeichen setzen:
	tst.l d2
	bpl.b ftd1
	bset #31,d0
ftd1	and.l #$7F800000,d2     ; Mantisse
	lsr.l #3,d2
	add.l #$3FF00000-($3F800000/8),d2
	or.l d2,d0
	move.l (a7)+,d2
	rts
ftdNull	moveq #0,d0
	moveq #0,d1
	rts

	END
