x2d() bug

A forum for general AmigaOS 4.x support questions that are not platform-specific
User avatar
polluks
Posts: 43
Joined: Tue May 19, 2015 6:30 pm
Location: Germany
Contact:

x2d() bug

Post 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
dstastny
Posts: 48
Joined: Fri Dec 16, 2016 6:31 am
Location: Atlanta GA

Re: x2d() bug

Post 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
User avatar
polluks
Posts: 43
Joined: Tue May 19, 2015 6:30 pm
Location: Germany
Contact:

Re: x2d() bug

Post 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
User avatar
thomasrapp
Posts: 299
Joined: Sat Jun 18, 2011 11:22 pm

Re: x2d() bug

Post by thomasrapp »

This applies only to the Kilowatt Software r4 implentation of Rexx. Arexx is 30 years older than that.
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1620
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: x2d() bug

Post by nbache »

thomasrapp wrote: Mon Sep 27, 2021 11:34 am
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
User avatar
polluks
Posts: 43
Joined: Tue May 19, 2015 6:30 pm
Location: Germany
Contact:

Re: x2d() bug

Post 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.
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1620
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: x2d() bug

Post by nbache »

polluks wrote: Thu Oct 07, 2021 9: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
User avatar
polluks
Posts: 43
Joined: Tue May 19, 2015 6:30 pm
Location: Germany
Contact:

Re: x2d() bug

Post by polluks »

Image
Well, the official documentation is "not very helpful". Even the square brackets are missing.
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1620
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: x2d() bug

Post 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
User avatar
polluks
Posts: 43
Joined: Tue May 19, 2015 6:30 pm
Location: Germany
Contact:

Re: x2d() bug

Post 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.
Post Reply