Post AZZOjs986iAzl3xjpw by PhilipKing@mastodon.social
 (DIR) More posts by PhilipKing@mastodon.social
 (DIR) Post #AZYsxnyvBuBQMXmt5U by EdS@mastodon.sdf.org
       2023-09-08T15:42:20Z
       
       0 likes, 1 repeats
       
       I think I've found a bug in a 1977 version of Basic...  I wonder if it's a new finding?110 A=SQR(2)120 B=SQR(3)130 C=SQR(6)140 PRINT A*B-C150 PRINT C-A*BTurns out A*B-C is non zero, which is fair and more or less expected, but C-A*B is different - it's zero - and I didn't expect that.This is of course Microsoft #Basic for the #Commodore #PET. The problem seems to be present in all their 6502 basics.https://www.masswerk.at/pet/?data=base64:MTEwIEE9U1FSKDIpCjEyMCBCPVNRUigzKQoxMzAgQz1TUVIoNikKMTQwIFBSSU5UIEEqQi1DCjE1MCBQUklOVCBDLUEqQg==&autorun=true#retroComputing #MSBasic
       
 (DIR) Post #AZYtU2B3wl4VempnP6 by spacemagick@mastodon.social
       2023-09-08T15:48:05Z
       
       0 likes, 0 repeats
       
       @EdS Ha!  Have you raised it with Commodore so they can fix it in the next version?:-)
       
 (DIR) Post #AZYwPzfFeFC0ZCih9c by Workshopshed@mastodon.scot
       2023-09-08T16:21:00Z
       
       0 likes, 0 repeats
       
       @EdS is it a bug or
       
 (DIR) Post #AZYxJVUH25aVBu3Wue by peter@area51.social
       2023-09-08T16:31:03Z
       
       0 likes, 0 repeats
       
       @EdS Sounds like it's not processing the equation correctly.C-A*B is actually non zero but too small for the float so it appears as zero.A*B-C is the same as above and is the same as (A*B)-C but it it looks like it's actually calculating A*(B-C), so the bug seems to be how it's parsing the equation.The problem is, how this type of algebra is parsed has changed over the decades so depends on which method the original author used
       
 (DIR) Post #AZZOjs986iAzl3xjpw by PhilipKing@mastodon.social
       2023-09-08T21:17:10Z
       
       0 likes, 0 repeats
       
       @peter @EdS I think the VIC20 programmers manual explains that all calculations are done right to left (except ^) but it’s been over thirty five years so I might be mis-remembering. (I tried to right a Mandelbrot set generator in CBM Basic)
       
 (DIR) Post #AZZOjt9sLQMotfJqdc by EdS@mastodon.sdf.org
       2023-09-08T21:38:21Z
       
       0 likes, 0 repeats
       
       Hmm, no, a quick test shows that precedence of multiplication and addition is as expected.In the extended discussion athttps://retrocomputingforum.com/t/investigating-basic-floating-point-accuracy-and-finding-a-bug/3588?u=edsyou'll find there's doubt about the clearing of one, but not both, floating point accumulators.> ZEROISE only applies to FAC#1, which may explain a lot, if one of the results in this comparison always remains in FAC#2.@PhilipKing @peter
       
 (DIR) Post #AZZaJf27RCTL0dx1yS by brouhaha@mastodon.social
       2023-09-08T23:48:01Z
       
       0 likes, 0 repeats
       
       @EdS I thought it was relatively well-known that in MS 6502 BASIC, addition is not commutative, and similarly subtraction. I'm pretty sure I first read about that in 1979 or 1980, but I don't recall where.
       
 (DIR) Post #AZaVc64XsVILP8y3oO by EdS@mastodon.sdf.org
       2023-09-09T07:16:41Z
       
       0 likes, 0 repeats
       
       > relatively well-known that in MS 6502 BASIC, addition is not commutativeAh, interesting - news to me! It would be excellent to find a book or magazine article from the time.I'd quite like to check MS's 8080 Basic, or other early Basic, and see if it is similarly afflicted.Because their later 6809 Basic is not affected, I think I'm right in regarding this as a flaw, or indeed a bug. I wonder how few bytes of code it would take to fix.@brouhaha
       
 (DIR) Post #AZb3zWtDM6ly1qjJZ2 by mnemonicoverload@libranet.de
       2023-09-09T08:39:02Z
       
       0 likes, 0 repeats
       
       @EdSThere's a fine line between flaw/bug and designing for a minimum viable system. I haven't looked at this particular aspect of MS BASIC myself yet but when you're targeting a language to tight constraints like fitting in a few KB of ROM or running within a few KB of working RAM space you can end up making some decisions that look absolutely wacky when removed from the original context.@brouhaha
       
 (DIR) Post #AZb3zYAcasI607sjKq by EdS@mastodon.sdf.org
       2023-09-09T16:55:16Z
       
       0 likes, 0 repeats
       
       I'm delighted to see that the mighty Bruce Clark posted about this multiplication bug - and several others - in 2019, including a length-preserving patch in this case.Klaus Dormann proceeded to produce a patched version of the #Basic in question, with annotated source.http://forum.6502.org/viewtopic.php?f=5&t=5606(It was #EhBasic, a modern derived work.)Admittedly I haven't yet applied and tested the patch to #Commodore #PET Basic.#retroComputing @mnemonicoverload @brouhaha
       
 (DIR) Post #AZdHeEJR170k0ReTVQ by EdS@mastodon.sdf.org
       2023-09-10T18:37:46Z
       
       0 likes, 0 repeats
       
       Update on my 1977-era #basic investigations: even with the various 2019 fixes, including a fix to multiplication rounding, I'm still seeing anomalous results.  Something is amiss in subtraction/comparison.#retroComputing