this post was submitted on 31 Aug 2023
46 points (96.0% liked)

retrocomputing

4159 readers
11 users here now

Discussions on vintage and retrocomputing

founded 2 years ago
MODERATORS
 

You are a BASIC bitch, so type-in and share your BASIC listings here. Any and all BASIC dialects are welcome.

you are viewing a single comment's thread
view the rest of the comments
[โ€“] over_clox@lemmy.world 3 points 1 year ago* (last edited 1 year ago) (1 children)

RapidQ integer rounding was totally broken, so I wrote this...


ABSVal# = ABS(Value#): SGNVal& = SGN(Value#)
	FIXVal& = FIX(ABSVal#): FRACVal# = FRAC(ABSVal#)
	AddVal& = (((FRACVal# = .5) AND FIXVal&) OR (FRACVal# > .5)) AND 1
	FIXVal& += AddVal&: IF SGNVal& = -1 THEN FIXVal& = -FIXVal&
	RQRoundFix = FIXVal&
END FUNCTION```
[โ€“] jadero@lemmy.sdf.org 2 points 1 year ago (1 children)

Are you sure that rounding was broken? Many systems use "Gaussian" or "banker's" rounding to reduce accumulation of rounding errors. Instead of always rounding to the next larger absolute value at .5, they round to the nearest even number. Although it introduces a bias toward even numbers in the result set, it reduces accumulation of error when .5 is as likely as as any other fraction and odd/even are equally likely in the source.

I was taught "banker's" rounding in school (graduated 1974) and have had to implement it a few times to reduce error accumulation.

If you are looking for a rabbit hole, Wikipedia has a pretty comprehensive article, including an example of how the wrong choice of rounding algorithm led to massive problems at the Vancouver Stock Exchange (Canada).