|
Post by rikky on Sept 13, 2020 10:14:46 GMT 1
Hello Sorry for reporting a (probable) bug in the wrong section, but the bug section is currently occupied by a question from Alexfish. I'm using the latest Fossil from today. From the documentation we have two examples: PRINT DEC("AB1E") PRINT DEC("00010101", 1) The response on the first command is 43806 The response on the second command however is: ERROR: signal for SEGMENTATION FAULT received - memory invalid or array out of bounds? Try to compile the program with TRAP LOCAL to find the cause. It becomes stranger even. string$ = "00010101" flag$ = "1"
PRINT "DEC(" & CHR$(34) & string$ & CHR$(34) & "," & flag$ & ")" PRINT DEC(string$,VAL(flag$)) Haha, now it works. Except it doesn't give the right answer. DEC("00010101",1) 65793 should be 1 + 4 + 16 = 21, or something. Rik.
|
|
|
Post by Pjot on Sept 13, 2020 13:33:53 GMT 1
Hi rikky, Thanks for your post. The cause of this issue is the documentation In fact, the last argument should lie between 2 and 36. So if you want to convert from a binary string, then the value should be '2': PRINT DEC("00010101", 2)
This will print the correct result '21' in decimal. I will update the documentation so it reflects the correct functionality. Also, I will add a check to make sure that the '1' cannot be used. Best regards Peter
|
|
|
Post by rikky on Sept 13, 2020 14:21:30 GMT 1
Nice. So now we can also recount octal values. I wasn't aware. PRINT DEC("112",8) Gives the correct value: 74 However the whole thing with variables still doesn't work. PRINT
string$ = "00010101" flag$ = "2"
PRINT "DEC(" & CHR$(34) & string$ & CHR$(34) & "," & flag$ & ")" PRINT DEC(string$,VAL(flag$)) PRINT "should be: " & STR$(DEC("00010101",2))
PRINT
string$ = "112" flag$ = "8"
PRINT "DEC(" & CHR$(34) & string$ & CHR$(34) & "," & flag$ & ")" PRINT DEC(string$,VAL(flag$)) PRINT "should be: " & STR$(DEC("112",8))
PRINT response: DEC("00010101",2) 65793 should be: 21
DEC("112",8) 274 should be: 74 Rik. PS: Am I missing OCT$(x) as a BaCon command?
|
|
|
Post by Pjot on Sept 13, 2020 14:28:37 GMT 1
Hi rikky, You code sample works fine for me: DEC("00010101",2) 21 should be: 21
DEC("112",8) 74 should be: 74
Can you try the latest BaCon from fossil and let me know your result?
Also I am curious on which platform you are testing?
BR Peter
|
|
|
Post by rikky on Sept 13, 2020 15:11:48 GMT 1
Oh, I was already using the latest version from this morning, but I'm fosseling a new one at this moment. I don't think it will make a difference. Is there a way to know what fossil version (creation date?) I'm using? (just to be able to cross check.) I'm using OS$ = Linux armv7l uname -r = 4.19.49v6v7-aufs (kernel) cat /etc/os-release = PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)" NAME="Raspbian GNU/Linux" VERSION_ID="9" VERSION="9 (stretch)" ID=raspbian ID_LIKE=debian HOME_URL="http://www.raspbian.org/" SUPPORT_URL="http://www.raspbian.org/RaspbianForums" BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs" Rik.
|
|
|
Post by rikky on Sept 13, 2020 15:31:27 GMT 1
Oh.... solved. The new fossil gives the right answers. I've absolutely no idea how that can be. If nothing changed in the source code around the DEC(x) routine, this should not be possible. But it is. I think it is impossible now to find the cause, so .. I supposed this one is solved. Thanks.. Rik.
|
|
|
Post by Pjot on Sept 13, 2020 19:02:30 GMT 1
Thanks Rik,
FYI: I have mapped the value '1' to '2' to maintain backwards compatibility.
Best regards, Peter
|
|