mirror of
https://github.com/byteworksinc/ORCALib.git
synced 2024-09-27 20:56:05 +00:00
e00c21dd70
These SANE operations can sometimes return incorrect values for certain negative integers such as -2147483648 and -53021371269120 (numbers with at least 16 low-order zero bits in their two's-complement representation). To work around this, we now avoid calling FX2C or FX2L on negative numbers, generally by saving and restoring the sign separately. These workarounds are used in several of the new <math.h> rounding functions, and also for code that converts floating-point values to comp or long long. There are some places in SysFloat that should be patched similarly, so we may still hit this problem in certain situations until that is done.
111 lines
2.4 KiB
NASM
111 lines
2.4 KiB
NASM
keep obj/fpextra
|
|
mcopy fpextra.macros
|
|
|
|
****************************************************************
|
|
*
|
|
* FPextra - extra floating-point routines
|
|
*
|
|
* This code provides routines dealing with floating-point
|
|
* numbers that are used only by ORCA/C, supplementing the
|
|
* ones in SysFloat.
|
|
*
|
|
****************************************************************
|
|
*
|
|
fpextra private dummy segment
|
|
end
|
|
|
|
****************************************************************
|
|
*
|
|
* ~SinglePrecision - limit fp value to single precision & range
|
|
*
|
|
* Inputs:
|
|
* extended-format real on stack
|
|
*
|
|
****************************************************************
|
|
*
|
|
~SinglePrecision start
|
|
tsc
|
|
clc
|
|
adc #4
|
|
ldy #0
|
|
phy
|
|
pha
|
|
phy
|
|
pha
|
|
phy
|
|
pha
|
|
phy
|
|
pha
|
|
FX2S
|
|
FS2X
|
|
rtl
|
|
end
|
|
|
|
****************************************************************
|
|
*
|
|
* ~DoublePrecision - limit fp value to double precision & range
|
|
*
|
|
* Inputs:
|
|
* extended-format real on stack
|
|
*
|
|
****************************************************************
|
|
*
|
|
~DoublePrecision start
|
|
tsc
|
|
clc
|
|
adc #4
|
|
ldy #0
|
|
phy
|
|
pha
|
|
phy
|
|
pha
|
|
phy
|
|
pha
|
|
phy
|
|
pha
|
|
FX2D
|
|
FD2X
|
|
rtl
|
|
end
|
|
|
|
****************************************************************
|
|
*
|
|
* ~CompPrecision - limit fp value to comp precision & range
|
|
*
|
|
* Inputs:
|
|
* extended-format real on stack
|
|
*
|
|
* Note: This avoids calling FX2C on negative numbers,
|
|
* because it is buggy for certain values.
|
|
*
|
|
****************************************************************
|
|
*
|
|
~CompPrecision start
|
|
lda 4+8,s
|
|
pha save original sign
|
|
asl a force sign to positive
|
|
lsr a
|
|
sta 6+8,s
|
|
tsc limit precision
|
|
clc
|
|
adc #6
|
|
ldy #0
|
|
phy
|
|
pha
|
|
phy
|
|
pha
|
|
phy
|
|
pha
|
|
phy
|
|
pha
|
|
FX2C
|
|
FC2X
|
|
pla restore original sign
|
|
bpl ret
|
|
lda 4+8,s
|
|
ora #$8000
|
|
sta 4+8,s
|
|
ret rtl
|
|
end
|
|
|