Error in Simple_Numbers library object
Phil Pilgrim (PhiPi)
Posts: 23,514
Here's the program:
Here's what gets output:
-Phil
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ pst : "Parallax Serial Terminal" num : "Simple_Numbers" PUB start | seed, value, best, worst, sum, n pst.start(9600) pst.str(num.decx(1_580_219_585, 10))
Here's what gets output:
0170154177
-Phil

Comments
"div * 10" in this case is over 32 bits.
Thanks. I hadn't bothered yet to find the cause, but I'm sure you're right.
-Phil
I think most of it originated in Tim Moore's four port serial object.
The number displays correctly with this modified method (there are actually two different methods used).
PUB Decx(value, digits) '' Prints zero-padded, signed-decimal string '' -- if value is negative, field width is digits+1 result := decl(value, digits, 2) PUB Decl(value, digits, flag) | localI, localX, localPtr '' DWD Fixed with FDX 1.2 code digits := 1 #> digits <# 10 localPtr := @nstr localX := value == NEGX 'Check for max negative if value < 0 value := ||(value + localX) 'If negative, make positive; adjust for max negative byte[localPtr++] := "-" localI := 1_000_000_000 if flag & 3 if digits < 10 ' less than 10 digits? repeat (10 - digits) ' yes, adjust divisor localI /= 10 repeat digits if value => localI byte[localPtr++] := value / localI + "0" + localX * (localI == 1) value //= localI result~~ elseif (localI == 1) OR result OR (flag & 2) byte[localPtr++] := "0" elseif flag & 1 byte[localPtr++] := " " localI /= 10 result := @nstrIt should be cleaned up before being added to Simple_Numbers officially.
Again, most of it is not my code.
-Phil