IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Floating point multiplication rules


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
niks_jude
Warnings : 1

Active User


Joined: 01 Dec 2006
Posts: 144
Location: Mumbai

PostPosted: Thu Aug 16, 2007 3:48 pm
Reply with quote

I have three fields.
x1 = 00.0010000 PIC S9(2)V9(7) COMP-3.
x2 = 0000.04025 PIC S9(4)V9(5) COMP-3.
x3 = 000100000.00 PIC S9(9)V9(2) COMP-3.

when I muilply these and the result is in comp-2(floating point field), the result is not 4.025E0 but 4.0249999999999999E+00.

Y = x1 * x2 * x3.

I read in the manuals that this is becuase all the fields are converted to floating point. How does this conversion take place? And how is the result justififed. I cannot use any other type field than floating point field.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Thu Aug 16, 2007 4:01 pm
Reply with quote

The primary problem is the total number of digist possible, your numbers are exceeding some limit the compiler uses in decieding how to do the calculation.
Floating point has a larger range but you may need to half round the result.
If x3 is always that large, pre calculating x1 * x3 and then multplying x2 to the intermediat total might keep everything decimal.....
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Thu Aug 16, 2007 4:09 pm
Reply with quote

Do you have any problem with the result?
The difference between two result is insignificant (1 * 10^-16). Unless you are doing scientific work the result should be OK for you.
I will suggest not going to the details of conversion because it is quite different from standard IEEE 754 and difficult to follow (Atleast to me).
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Aug 16, 2007 4:20 pm
Reply with quote

niks_jude wrote:

x1 = 00.0010000 PIC S9(2)V9(7) COMP-3.
x2 = 0000.04025 PIC S9(4)V9(5) COMP-3.
x3 = 000100000.00 PIC S9(9)V9(2) COMP-3.

The compiler only sees the max size possible:
2+4+9 & 7+5+2 or S9(15)v9(14)
which exceeds the ARITH(COMPAT) compiler option of 18 digits.
Try the compiler option of ARITH(EXTEND) which allows 31 digits.
Back to top
View user's profile Send private message
niks_jude
Warnings : 1

Active User


Joined: 01 Dec 2006
Posts: 144
Location: Mumbai

PostPosted: Thu Aug 16, 2007 9:14 pm
Reply with quote

I cannot try with x3 = x1 * x3
and y = x3 * x2.
because it may lead to truncation in extreme conditions.

Do I have any other option.

Because its a production problem, In cannot change the compiler option also.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Thu Aug 16, 2007 9:31 pm
Reply with quote

niks_jude wrote:
I cannot try with x3 = x1 * x3
and y = x3 * x2.
because it may lead to truncation in extreme conditions.
Heck, we couldn't have that.... max conditions would exceed 18 total digits....
Quote:
Do I have any other option.
Change the compiler option....
Quote:
Because its a production problem, In cannot change the compiler option also.
Now this does not make sense, it is a compile option, not a runtime option.
Any method you use to fix this will require a compile, you can't deny that and if a different compile option will fix it, use it - that's what they are there for.......
Or just half round and live with the close answer.....
Back to top
View user's profile Send private message
niks_jude
Warnings : 1

Active User


Joined: 01 Dec 2006
Posts: 144
Location: Mumbai

PostPosted: Thu Aug 16, 2007 9:35 pm
Reply with quote

This would require the production compiler options to be chnaged which is not feasible. As other elements may get out of synch.

Is it possible to do this with tricky use of intermediate variables?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Aug 16, 2007 9:45 pm
Reply with quote

I believe that you can include Compiler Options in the source. That would remove the 'special' compiliation circumstances.

Not knowing what kind of application is in use hinders 'work around solutions'. I have worked for banks and transportation companies - neither of which ever required floating point. So, I can't (should not) make any rash judgements or decisions....... but, why is their only one module in the company that requires this kind of arithmetics?
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Thu Aug 16, 2007 9:48 pm
Reply with quote

niks_jude wrote:
This would require the production compiler options to be chnaged which is not feasible. As other elements may get out of synch.
Wrong, the "production compiler options" can be overridden and/or supplemented within the COBOL source code itself and would only apply to that one module.
Quote:
Is it possible to do this with tricky use of intermediate variables?
I could not see any reasonable way that would not exceed 18 digits.....
Back to top
View user's profile Send private message
niks_jude
Warnings : 1

Active User


Joined: 01 Dec 2006
Posts: 144
Location: Mumbai

PostPosted: Thu Aug 16, 2007 11:28 pm
Reply with quote

Thanks I would have to ask the senior guys if this is allowed in our production environmenr.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Aug 17, 2007 1:05 am
Reply with quote

Hello,

Quote:
Is it possible to do this with tricky use of intermediate variables

It is a guarantee that you do not want to seek and or use some "tricky thing" even if you find one that you think might work. . .

I am not clear on why you have used floating-point for your result. If you use
Code:
  77  FLD-X1              PIC S9(2)V9(7) COMP-3.     
  77  FLD-X2              PIC S9(4)V9(5) COMP-3.     
  77  FLD-X3              PIC S9(9)V9(2) COMP-3.     
  77  FLD-Y               PIC S9(9)V9(9) COMP-3.     
  77  FLD-Y-PRT           PIC 9(9).9(9).             

        MOVE 00.0010000 TO FLD-X1.                     
        MOVE 0000.04025 TO FLD-X2.                     
        MOVE 000100000.00 TO FLD-X3.                   
        COMPUTE FLD-Y = FLD-X1 * FLD-X2 * FLD-X3.     
        MOVE FLD-Y TO FLD-Y-PRT.                       
        DISPLAY FLD-Y.                                 
        DISPLAY FLD-Y-PRT.                             
 

you get
Code:
000000004025000000
000000004.025000000
which i believe is correct. . .

You can shift the number of digits depending on your requirement, but i believe you would be able to work within 18 digits.
Back to top
View user's profile Send private message
niks_jude
Warnings : 1

Active User


Joined: 01 Dec 2006
Posts: 144
Location: Mumbai

PostPosted: Fri Aug 17, 2007 10:12 am
Reply with quote

No the requirement is following ---------

Use floating point till last step. In the last step round the floating point result to two decimal places.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Aug 17, 2007 1:55 pm
Reply with quote

niks_jude wrote:
No the requirement is following ---------

Use floating point till last step. In the last step round the floating point result to two decimal places.
Well then, do it......
Do you know how to round the result to two decimals?
Back to top
View user's profile Send private message
niks_jude
Warnings : 1

Active User


Joined: 01 Dec 2006
Posts: 144
Location: Mumbai

PostPosted: Fri Aug 17, 2007 2:38 pm
Reply with quote

Yes. I thought of using some intemediate flaoting variables so that the dip in value is not there.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Aug 17, 2007 2:45 pm
Reply with quote

Won't help, just half round and be done with it.....
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Aug 17, 2007 8:33 pm
Reply with quote

Hello,

Please explain the requirement that restricts the process to floating point. I do not understand such a requirement for what it appears you need to accomplish.

What business reason dictates this? If there is no business reason, using standard arithmetic would be a better choice.
Back to top
View user's profile Send private message
niks_jude
Warnings : 1

Active User


Joined: 01 Dec 2006
Posts: 144
Location: Mumbai

PostPosted: Sat Aug 18, 2007 11:52 am
Reply with quote

We have been provided this in design specifications and we have to abide by it. Even I cannot really understand the requirement but I have to strictly follow the design specifications. Thanks.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Point and Shoot )PTNS TSO/ISPF 0
No new posts A directory in the pathname was not f... ABENDS & Debugging 0
No new posts How to remove DECIMAL POINT (.) from ... SYNCSORT 10
No new posts Data set not migrated even though all... JCL & VSAM 10
No new posts RULES(NOEVENPACK) in cobol COBOL Programming 5
Search our Forums:

Back to Top