1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-10-18 22:24:28 +00:00

Consistent SANE API naming

This commit is contained in:
David Schmenk 2017-12-15 11:28:04 -08:00
parent b6d7986249
commit 35da78ce92

View File

@ -138,8 +138,8 @@ def str2ext(str, ext)
decrec.sig.1 = '0' decrec.sig.1 = '0'
fin fin
//putc(decrec.sgn ?? '-' :: '+'); puts(@decrec.sig); putc('e'); puti(decrec:exp); putln //putc(decrec.sgn ?? '-' :: '+'); puts(@decrec.sig); putc('e'); puti(decrec:exp); putln
sane:zpSave() sane:saveZP()
return sane:zpRestore(sane:fpOp2(FFEXT|FOD2B, ext, @decrec)) return sane:restoreZP(sane:op2FP(FFEXT|FOD2B, ext, @decrec))
end end
def ext2str(ext, str, intdigits, fracdigits, format) def ext2str(ext, str, intdigits, fracdigits, format)
byte d, i, sigdigits, numdigits byte d, i, sigdigits, numdigits
@ -150,8 +150,8 @@ def ext2str(ext, str, intdigits, fracdigits, format)
numdigits = intdigits + fracdigits numdigits = intdigits + fracdigits
decform:style = format & $01 decform:style = format & $01
decform:digits = decform:style ?? fracdigits :: numdigits decform:digits = decform:style ?? fracdigits :: numdigits
sane:zpSave() sane:saveZP()
sane:zpRestore(sane:fpOp3(FFEXT|FOB2D, @decrec, ext, @decform)) sane:restoreZP(sane:op3FP(FFEXT|FOB2D, @decrec, ext, @decform))
^(str+1) = decrec.sgn ?? '-' :: ' ' ^(str+1) = decrec.sgn ?? '-' :: ' '
if decrec.sig.1 == 'I' if decrec.sig.1 == 'I'
^(str+2) = 'I' ^(str+2) = 'I'
@ -269,9 +269,9 @@ def divstri(strNum, denom, format)#0
// Convert string to and from SANE // Convert string to and from SANE
// //
str2ext(strNum, @xResult) str2ext(strNum, @xResult)
sane:zpSave() sane:saveZP()
sane:fpOp2(FFINT|FODIV, @xResult, @denom) // Div int denom into ext Result sane:op2FP(FFINT|FODIV, @xResult, @denom) // Div int denom into ext Result
sane:zpRestore(0) sane:restoreZP(0)
ext2str(@xResult, @strResult, 6, 4, format)//format & $05 ?? 1 :: 6, 4, format) ext2str(@xResult, @strResult, 6, 4, format)//format & $05 ?? 1 :: 6, 4, format)
puts(strNum); putc('/'); puti(denom); putc('='); puts(@strResult); putln puts(strNum); putc('/'); puti(denom); putc('='); puts(@strResult); putln
end end
@ -279,7 +279,7 @@ end
// My custom SANE exception handler // My custom SANE exception handler
// //
def myException(pstatus) def myException(pstatus)
sane:zpRestore(0) sane:restoreZP(0)
puts("Floating point exception:") puts("Floating point exception:")
if pstatus->8 & FBINVALID; puts(" INVALID"); fin if pstatus->8 & FBINVALID; puts(" INVALID"); fin
if pstatus->8 & FBUFLOW; puts(" UNDERFLOW"); fin if pstatus->8 & FBUFLOW; puts(" UNDERFLOW"); fin
@ -287,7 +287,7 @@ def myException(pstatus)
if pstatus->8 & FBDIVZER; puts(" DIV_BY_ZERO"); fin if pstatus->8 & FBDIVZER; puts(" DIV_BY_ZERO"); fin
if pstatus->8 & FBINEXACT; puts(" INEXACT"); fin if pstatus->8 & FBINEXACT; puts(" INEXACT"); fin
putln putln
sane:zpSave() sane:saveZP()
return pstatus=>4 return pstatus=>4
end end
@ -297,40 +297,40 @@ iB = 4
iC = -1 iC = -1
zero = 0 zero = 0
puts("SANE sanity test...\n") puts("SANE sanity test...\n")
sane.fpInit() sane.initFP()
sane:zpSave() sane:saveZP()
sane:fpOp2(FFINT|FOZ2X, @xT, @iA) // Convert int A to ext T sane:op2FP(FFINT|FOZ2X, @xT, @iA) // Convert int A to ext T
sane:fpOp2(FFINT|FOADD, @xT, @iB) // Add int B to ext T sane:op2FP(FFINT|FOADD, @xT, @iB) // Add int B to ext T
sane:fpOp2(FFINT|FOX2Z, @iC, @xT) // Convert ext T to int C sane:op2FP(FFINT|FOX2Z, @iC, @xT) // Convert ext T to int C
sane:zpRestore(0) sane:restoreZP(0)
puti(iA); putc('+'); puti(iB); putc('='); puti(iC); putc('\n') puti(iA); putc('+'); puti(iB); putc('='); puti(iC); putc('\n')
sane:zpSave() sane:saveZP()
sane:fpOp2(FFINT|FOZ2X, @xT, @iA) // Convert int A to ext T sane:op2FP(FFINT|FOZ2X, @xT, @iA) // Convert int A to ext T
sane:fpOp2(FFINT|FOSUB, @xT, @iB) // Sub int B from ext T sane:op2FP(FFINT|FOSUB, @xT, @iB) // Sub int B from ext T
sane:fpOp2(FFINT|FOX2Z, @iC, @xT) // Convert ext T to int C sane:op2FP(FFINT|FOX2Z, @iC, @xT) // Convert ext T to int C
sane:zpRestore(0) sane:restoreZP(0)
puti(iA); putc('-'); puti(iB); putc('='); puti(iC); putc('\n') puti(iA); putc('-'); puti(iB); putc('='); puti(iC); putc('\n')
sane:zpSave() sane:saveZP()
sane:fpOp2(FFINT|FOZ2X, @xT, @iA) // Convert int A to ext T sane:op2FP(FFINT|FOZ2X, @xT, @iA) // Convert int A to ext T
sane:fpOp2(FFINT|FOMUL, @xT, @iB) // Mul int B by ext T sane:op2FP(FFINT|FOMUL, @xT, @iB) // Mul int B by ext T
sane:fpOp2(FFINT|FOX2Z, @iC, @xT) // Convert ext T to int C sane:op2FP(FFINT|FOX2Z, @iC, @xT) // Convert ext T to int C
sane:zpRestore(0) sane:restoreZP(0)
puti(iA); putc('*'); puti(iB); putc('='); puti(iC); putc('\n') puti(iA); putc('*'); puti(iB); putc('='); puti(iC); putc('\n')
sane:zpSave() sane:saveZP()
sane:fpOp2(FFINT|FOZ2X, @xT, @iA) // Convert int A to ext T sane:op2FP(FFINT|FOZ2X, @xT, @iA) // Convert int A to ext T
sane:fpOp2(FFINT|FODIV, @xT, @iB) // Div int B into ext T sane:op2FP(FFINT|FODIV, @xT, @iB) // Div int B into ext T
sane:fpOp2(FFINT|FOX2Z, @iC, @xT) // Convert ext T to int C sane:op2FP(FFINT|FOX2Z, @iC, @xT) // Convert ext T to int C
sane:zpRestore(0) sane:restoreZP(0)
puti(iA); putc('/'); puti(iB); putc('='); puti(iC); putc('\n') puti(iA); putc('/'); puti(iB); putc('='); puti(iC); putc('\n')
// //
// Hook custom HALT exception handler and divide by zero :-) // Hook custom HALT exception handler and divide by zero :-)
// Enable all exceptions // Enable all exceptions
// //
sane:zpSave() sane:saveZP()
sane:fpHalt = @myException sane:haltFP = @myException
fpEnv = sane:fpOp0(FOGETENV) fpEnv = sane:op0FP(FOGETENV)
sane:fpOp1(FOSETENV, fpEnv | FBINVALID | FBUFLOW | FBOFLOW | FBDIVZER | FBINEXACT) sane:op1FP(FOSETENV, fpEnv | FBINVALID | FBUFLOW | FBOFLOW | FBDIVZER | FBINEXACT)
sane:zpRestore(0) sane:restoreZP(0)
// //
// String conversion tests // String conversion tests
// //