open-simh.simtools/tests/test-prec.mac
Bjoren Davis 6f7e7963bc small (1 and 2 word) floating point literals not parsed correctly
Fix gitlab issue #5.

The parse_float() function has several bugs:

    1. For 1- and 2-word floats it will always write all 4 bytes if the value is
       exactly 0.
    2. It incorrectly rounds and normalizes 1- and 2-word floats.

To see the issue easily try the following inputs:

     .flt2  1.0
     .flt4  1.0

These will assemble as '040100 000000' and '040200 000000 000000 000000'.
They should both begin '040200'.

In fact the test file test/test-prec.mac is incorrect in its only floating point value:
	.word	^f 1.5		; 040140
should actually assemble as 040300, not 040140 (040140 is actually ^F0.875).
I confirmed this on RT-11 running MACRO V05.06.

I fixed the problem with the following deltas:

[the patch]

The most crucial change is the very last one. 0x200000000000 is actually (1 << 45)
and because ufrac is normalized it means that it will always downshift ufrac by 1.
2021-01-18 20:22:34 +01:00

59 lines
1.5 KiB
Plaintext

;;;;;
;
; Test operator precedencce
; or rather the lack thereof
;
.word 1 + 2 + 3 ; 6
.word 1 + 2 * 3 ; 3*3 = 11
.word 1 & 2 ! 4 ; 0 ! 4 = 4
.word 1 ! 2 & 4 ; 3 & 4 = 0
.word 1 ! 2 & 7 ; 3 & 7 = 3
.word 1+1 ! 2+3 ; 2!2+3 = 2+3 = 5
;;;;;
;
; Test all operators at least once
;
.word 3 + 4 ; 000007
.word 4 - 3 ; 000001
.word 3 * 4 ; 000014
.word 12. / 4 ; 000003
.word 123 & 771 ; 000121
.word 123121 ! 322 ; 123323
.word - 377 ; 177401
.word + 377 ; 000377
.word ^C 377 ; 177400
.word ^c 377 ; 177400
.word ^B 0101010101010101 ; 052525
.word ^b 1010101010101010 ; 125252
.word ^d 100 ; 000144
.word 100. ; 000144
.word ^x 100 ; 000400 hexadecimal is an extension
.word ^rRAD ; 070254 up to 3 characters; no leading spaces
.word ^rA ; 003100 up to 3 characters
.word ^r A ; 000050 up to 3 characters
.word ^r A ; 000001 up to 3 characters
.word ^r AA ; 000051
.word ^rA A ; 003101
.word ^rAA ; 003150
.word ^r^/AAA/ ; bracketed strings are an extension
.word ^r<RAD> ; bracketed strings are an extension
.word ^r< AD> ; bracketed strings are an extension
.word ^r< D> ; bracketed strings are an extension
.word ^r<R D> ; bracketed strings are an extension
.word ^r<RA > ; bracketed strings are an extension
.word ^R50. ; 157614 there is no whitespace in between.
.word ^f 1.5 ; 040300
;;;;;
;
; Test bracketing
;
.word 1 + < 2 * 3 > ; 1 + 6 = 7
.word 1 + ^! 2 * 3 ! ; 1 + 6 = 7
.word 1 + ^/ 2 * 3 / ; 1 + 6 = 7
.word 1 + ^$ 2 * 3 $ ; 1 + 6 = 7
.word 1 + ^* 2 * 3 * ; Invalid expression