Decimal Arithmetic, the Host Language and Object-oriented programming

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Decimal Arithmetic, the Host Language and Object-oriented programming

Jason Martin
After thinking more about the method below, I have some questions.

method hashCode returns int
  if chars=null then chars=layout()
  if chars.length<14 then over=(chars.length+1)%2
                     else over=7
  /* Hash the first and last OVER characters */
  hash=0
  loop i=0 to over-1
    hash=hash*7+int(chars[i])*2+int(chars[chars.length-i-1])
    end i
  return hash

It returns a Java Integer in the range from -2,147,483,648 to +2,147,483,647.

But in this case, the math inside the method is done with the Rexx type.

Rexx does not have any problem with the math and large numbers,
 so to it, there was never a error when the value exceeded 2,147,483,647.

A hash was always returned and no errors shown.

When Java seen the number exceeded the integer limits in the return value did it?

1) Go to the parent class and use that method

2) Did the JVM return some number on its stack

Also, is there a way to catch this type of bug before hand?


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Decimal Arithmetic, the Host Language and Object-oriented programming

rickmcguire
If this is generating a hash code like the Java string class, the hash is intended to overflow during the calculation, so there is no problem. 

Rick

On Wed, Aug 1, 2018 at 9:02 AM Jason Martin <[hidden email]> wrote:
After thinking more about the method below, I have some questions.

method hashCode returns int
  if chars=null then chars=layout()
  if chars.length<14 then over=(chars.length+1)%2
                     else over=7
  /* Hash the first and last OVER characters */
  hash=0
  loop i=0 to over-1
    hash=hash*7+int(chars[i])*2+int(chars[chars.length-i-1])
    end i
  return hash

It returns a Java Integer in the range from -2,147,483,648 to +2,147,483,647.

But in this case, the math inside the method is done with the Rexx type.

Rexx does not have any problem with the math and large numbers,
 so to it, there was never a error when the value exceeded 2,147,483,647.

A hash was always returned and no errors shown.

When Java seen the number exceeded the integer limits in the return value did it?

1) Go to the parent class and use that method

2) Did the JVM return some number on its stack

Also, is there a way to catch this type of bug before hand?

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Decimal Arithmetic, the Host Language and Object-oriented programming

Jason Martin
In reply to this post by Jason Martin
So, the overflow is reduced to a correct integer or just some allowable
integer in conversion?

Should the fix that was committed be backed out.

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Decimal Arithmetic, the Host Language and Object-oriented programming

rickmcguire
The overflow just causes a wrap around on the integer. This is defined in the Java architecture. The intent of the hash is to produce an integer value that contains contributions from all of the characters. This is still accomplished even after it wraps. If the fix was somehow to prevent the overflow, then I think yes, it should be backed out. 

Rick

On Wed, Aug 1, 2018 at 1:21 PM Jason Martin <[hidden email]> wrote:
So, the overflow is reduced to a correct integer or just some allowable
integer in conversion?

Should the fix that was committed be backed out.

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Decimal Arithmetic, the Host Language and Object-oriented programming

Jason Martin
In reply to this post by Jason Martin
René can you back the hashcode fix out for me?

I did not fully understand the logic behind the method.

For me, it seemed to be a math error.

Not sure I still get the concept though.

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/