diff --git a/doc/DRAWL.md b/doc/DRAWL.md index 93db4d8..e072772 100644 --- a/doc/DRAWL.md +++ b/doc/DRAWL.md @@ -158,6 +158,8 @@ LISP 1.5 Manual: https://archive.org/details/bitsavers_mitrlelisprammersManual2e LISP 1.5 Primer: https://www.softwarepreservation.org/projects/LISP/book/Weismann_LISP1.5_Primer_1967.pdf +P-LISP Manual (newer than LISP 1.5): https://archive.org/details/gLISP/gnosisLISPManual + Apple Numerics Manual (SANE): https://vintageapple.org/inside_o/pdf/Apple_Numerics_Manual_Second_Edition_1988.pdf Video showing DRAWL in action: https://youtu.be/wBMivg6xfSg diff --git a/src/lisp/s-math.pla b/src/lisp/s-math.pla index 5568cdc..a90e4e4 100644 --- a/src/lisp/s-math.pla +++ b/src/lisp/s-math.pla @@ -710,28 +710,38 @@ def natv_shift(symptr, expr) // // Shift right // - while shift < 0 - bitval[0] = bitval[0] >> 1 - if bitval[1] & 1 - bitval[0] = bitval[0] | $8000 - else - bitval[0] = bitval[0] & $7FFF - fin - bitval[1] = bitval[1] >> 1 - shift++ - loop + if shift < -31 + bitval[1] = bitval[1] < 0 ?? $FFFF :: 0 + bitval[0] = bitval[1] + else + while shift < 0 + bitval[0] = bitval[0] >> 1 + if bitval[1] & 1 + bitval[0] = bitval[0] | $8000 + else + bitval[0] = bitval[0] & $7FFF + fin + bitval[1] = bitval[1] >> 1 + shift++ + loop + fin else // // Shift left // - while shift > 0 - bitval[1] = bitval[1] << 1 - if bitval[0] & $8000 - bitval[1] = bitval[1] | 1 - fin - bitval[0] = bitval[0] << 1 - shift-- - loop + if shift > 31 + bitval[0] = 0 + bitval[1] = 0 + else + while shift > 0 + bitval[1] = bitval[1] << 1 + if bitval[0] & $8000 + bitval[1] = bitval[1] | 1 + fin + bitval[0] = bitval[0] << 1 + shift-- + loop + fin fin return new_int(bitval[0], bitval[1]) end @@ -746,6 +756,7 @@ def natv_rotate(symptr, expr) symptr = eval_int(expr=>cdr) rotate = symptr=>intval[0] if rotate < 0 + rotate = rotate | $FFFFFFE0 while rotate < 0 wrap = bitval[0] & 1 ?? $8000 :: 0 bitval[0] = bitval[0] >> 1 @@ -758,6 +769,7 @@ def natv_rotate(symptr, expr) rotate++ loop else + rotate = rotate & $0000001F while rotate > 0 wrap = bitval[1] & $8000 ?? 1 :: 0 bitval[1] = bitval[1] << 1