Page 1 of 2

x2d() bug

Posted: Thu Sep 16, 2021 10:11 pm
by polluks
Maybe you don't know why

Code: Select all

rx "say x2d(f) x2d(f,1)"
15 -1
because of http://www.rexxinfo.org/html/functions.html#x2d

Code: Select all

/**/
do i=1 to 8
	say copies(8,i)"09"x x2d(copies(8,i))"09"x x2d(copies(8,i),1)
end
You see the bug at the last line, so 50% of all 1-parameter calls are wrong
8 8 -8
88 136 -8
888 2184 -8
8888 34952 -8
88888 559240 -8
888888 8947848 -8
8888888 143165576 -8
88888888 -2004318072 -8

Re: x2d() bug

Posted: Sat Sep 25, 2021 5:10 pm
by dstastny
I am not familiar that much with the AREXX subsystem but considering the nature of a 32bit OS and the age of this subsystem this is a mathematically limitation of a signed 32 bit integer. This looping algorithm exceeds the maximum value of a "signed" integer. When the high bit gets set in which is set for twos compliment implementation for signed numbers it flips to negative. The answers is not wrong bug mathematically looks correct. If the underlying datatype was a int 64 you would probably see the result you are looking for.

If you want to see example feed FFFFFFFF to the routine and you will see -1

Regards
Doug

Re: x2d() bug

Posted: Sun Sep 26, 2021 9:07 pm
by polluks
Please take care of the number of arguments defined by TRL-2:
1 parameter → unsigned (size independent definition)
2 parameters → signed

"4. The largest X2D numeric argument is 'FFFFFFFFFFFFFFFF'x => 18446744073709551615."
http://www.manmrk.net/tutorials/rexx/R4 ... tionLimits

Re: x2d() bug

Posted: Mon Sep 27, 2021 12:34 pm
by thomasrapp
This applies only to the Kilowatt Software r4 implentation of Rexx. Arexx is 30 years older than that.

Re: x2d() bug

Posted: Mon Sep 27, 2021 4:27 pm
by nbache
thomasrapp wrote: Mon Sep 27, 2021 12:34 pm
This applies only to the Kilowatt Software r4 implentation of Rexx. Arexx is 30 years older than that.
Indeed. Although Polluks also refers to TRL-2, I assume that means the book "The Rexx Language", second edition, by Mike Cowlishaw, and that came out in 1990.

Perhaps more importantly, ARexx is not a 1 to 1 implementation of Rexx. Some parts of Rexx are not included in ARexx, some are implemented differently, while a number of additions over the original Rexx were also made for ARexx.

The best reference for how ARexx should behave is and will always be the original documentation from Bill Hawes. A close second is the ARexxGuide from Aminet.

As for whether the described behaviour is a bug in regards to those references, sorry, I have no idea.

Best regards,

Niels

Re: x2d() bug

Posted: Thu Oct 07, 2021 10:48 pm
by polluks
Niels,

In the ARexx User's Reference Manual I cannot find x2d at all.
Maybe it's not a bug but some kind of undefined behavior.

Re: x2d() bug

Posted: Fri Oct 08, 2021 12:25 am
by nbache
polluks wrote: Thu Oct 07, 2021 10:48 pmIn the ARexx User's Reference Manual I cannot find x2d at all.
I'm not sure of the whereabouts of all my various generations of manuals, but I just looked in the ARexx section of the big binder set, I think it came with 2.0? in that, the x2d() function is described on page 10-124.

For daily ARexx reference, i always use the excellent ARexxGuide from Aminet, and it also documents this function.

Best regards,

Niels

Re: x2d() bug

Posted: Sun Oct 17, 2021 11:36 pm
by polluks
Image
Well, the official documentation is "not very helpful". Even the square brackets are missing.

Re: x2d() bug

Posted: Mon Oct 18, 2021 1:40 am
by nbache
Yeah, it's the same in that old binder version I mentioned above. And I just found one of my sets of 3.1 manuals, and the Rexx book there has the same error.

Oh well, we're not going to see that corrected by now in those print manuals.

I'll see if I can find someone who is able to fix the version on wiki.amigaos.net at least.

Best regards,

Niels

Re: x2d() bug

Posted: Mon Oct 18, 2021 8:50 pm
by polluks
https://wiki.amigaos.net/wiki/AmigaOS_M ... #X2D.28.29 is fixed, however nothing about signed/unsigned.
Well, I can live with that.