mvslovers / brexx370

MVS version of Vasilis Vlachoudis awesome rexx implementation
45 stars 11 forks source link

improper integer arithmetic #110

Open TheFausap opened 7 months ago

TheFausap commented 7 months ago

Hello, I installed tk5 with the latest BREXX370 version. I suppose also this behaviour could be relate to the other open issue TRUNCATE ROUDING. The source is

SAY TIME(); SAY DATE()                        
NUMERIC DIGITS 60                             
SAY 'THERE ARE' DIGITS() 'DIGITS OF PRECISION'
RSLT = 6**6**6                                
SAY '6^6^6 =' RSLT                            
EXIT                                          
19:18:48                             
28/01/2024                           
THERE ARE 60 DIGITS OF PRECISION     
6^6^6 = 10314424798490544000000000000

I tried also with an online interpreter (https://www.tutorialspoint.com/execute_rexx_online.php), and I have the correct result

18:17:11
28 Jan 2024
THERE ARE 60 DIGITS OF PRECISION
6^6^6 = 10314424798490535546171949056
rvjansen commented 7 months ago

This is to be expected. From the manual (BREXX370_Users_Guide_V2R5M2.pdf):

BREXX supports two numeric types: Integer

Integers are stored in 4 bytes a full word (LONG), this means their range is from -2,147,483,648 to +2,147,483,647

Decimal Numbers Decimal Numbers (decimal numbers with a fractional part) are represented in the double-precision floating- point format (doubleword), the length is 8 bytes consisting of an exponent and the significand (fraction). It consists of 56 bits for the fraction part, a 7-bit exponent and one-bit for the sign. This representation is IBM- specific and differs slightly from the IIEE 754 floating-point standard. The precision of floating-point numbers is not as good as decimal packed numbers which are not supported in BREXX (nor in REXX). This means, for example, 2.0 might be stored as 19999999999999999e-17, or for 5.0 you will is stored as 50000000000000003e-17; this is not an error, but the usual behaviour for floating-point numbers. It is caused by the conversion between the numbers of base 10 to base two a bit-exact reversibility is not always given. This effect may build up during arithmetic calculations.

BREXX might or might not gain the unlimited decimal precision arithmetic; at the moment it does not have it.