View previous topic :: View next topic
|
Author |
Message |
soundarr
New User
Joined: 17 Jan 2008 Posts: 25 Location: Chennai
|
|
|
|
Dear All,
Strangely, I get a zerodivide error condition raised for the below statement. Can you please confirm if 0.01 is not accepted by the DIVIDE function or if I am missing something.
Code: |
DCL A FIXED(15,9) INIT(0);
DCL B FIXED(15,2) INIT(0);
DCL C FIXED(15,2) INIT(0);
B = 10;
C = 0.01;
A = DIVIDE(B,C,15,9);
|
It works if C is 0.02.
Thanks,
Soundar |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Look at the binary representation of 0.01 and compare it to your FIXED BIN(15,2).
Also, why did you not just print the values of B and C? |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
I believe that you may not be correct, Robert. IIRC, the default base of an arithmetic variable is DECIMAL (although Soundar-kun ought to declare that explicitly, lest some software engineer assigned to maintain the program add a DEFAULT statement that changes that). |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
I still wonder why a forum post instead of just printing the value of C to see what it is. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
May you want to check the compiler options used. |
|
Back to top |
|
|
soundarr
New User
Joined: 17 Jan 2008 Posts: 25 Location: Chennai
|
|
|
|
B and C are printed as 10 and 0.01 as assigned. |
|
Back to top |
|
|
soundarr
New User
Joined: 17 Jan 2008 Posts: 25 Location: Chennai
|
|
|
|
DEC FIXED(15,2) gives the same result. |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
soundarr wrote: |
Dear All,
Strangely, I get a zerodivide error condition raised for the below statement. Can you please confirm if 0.01 is not accepted by the DIVIDE function or if I am missing something.
Code: |
DCL A FIXED(15,9) INIT(0);
DCL B FIXED(15,2) INIT(0);
DCL C FIXED(15,2) INIT(0);
B = 10;
C = 0.01;
A = DIVIDE(B,C,15,9); |
It works if C is 0.02. |
The above code compiles and executes flawlessly with
- OS PL/I V2.3.0
- Enterprise PL/I V3.3
- Enterprise PL/I V3.5
- Enterprise PL/I V3.7
- Enterprise PL/I V3.9
- Enterprise PL/I V4.3
Ergo conclusio: You're talking utter BS. Your zerodivide occurs somewhere else! The arrogant imbecility of assuming that c=0.01 would cause it is breathtaking. |
|
Back to top |
|
|
soundarr
New User
Joined: 17 Jan 2008 Posts: 25 Location: Chennai
|
|
|
|
Thanks Prino. My apologies to you and all for giving an example of 10 instead of 10000 which I actually used. Please excuse me.
When I used 10000 for B. It divided 10000 by 0.01 which will be 1000000. But since A is 15,9 which leaves only 6 bytes for whole numbers thus unable to hold the 7 digit result. This results in a decimal divide exception which also raises a zero divide exception causing the confusion.
So, it was not a zero divide actually but the system did raise it.
Regards,
Soundar |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Do you mean a Decimal Divide Exception (S0CB)? I'm not aware of an actual "zero divide" exception, perhaps you can tell us the system abend code for that?
If you divide and the result overflows the receiving field, you get S0CB unless it is "handled" in the programming language. |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
I think that ZERODIVIDE is a PL/I condition; the environment distinguishes this from other errors that would cause a S0CB abend to occur. |
|
Back to top |
|
|
soundarr
New User
Joined: 17 Jan 2008 Posts: 25 Location: Chennai
|
|
|
|
SOCB (decimal divide exception) was the abend code, but the statements inside ON ZERODIVIDE section were executed. |
|
Back to top |
|
|
|