Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

REXX Function to Change exponential to decimal

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
View previous topic :: :: View next topic  
Author Message
Soundammal.S

New User


Joined: 05 May 2008
Posts: 29
Location: Chennai

PostPosted: Wed Dec 09, 2009 3:01 pm    Post subject: REXX Function to Change exponential to decimal
Reply with quote

Hello ,

I'm working on REXX code in which I have got some values in exponential form. But I need to change it to decimal format.Need help in this.

Thank you.
Back to top
View user's profile Send private message

expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Wed Dec 09, 2009 3:05 pm    Post subject:
Reply with quote

What have you researched for yourself and what problems did you encounter ?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Dec 09, 2009 6:33 pm    Post subject:
Reply with quote

Soundammal.S wrote:
values in exponential form


I am just a dumb old programmer, could you please explain what you mean by exponential form
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Wed Dec 09, 2009 10:04 pm    Post subject:
Reply with quote

Hello,

As with many things, it will help if you post some samples of what you "have" and what you "want as output" when your process runs. . .
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Wed Dec 09, 2009 10:20 pm    Post subject:
Reply with quote

Or post "what you have not"?
Back to top
View user's profile Send private message
prino

Active Member


Joined: 07 Feb 2009
Posts: 982
Location: Oostende, Belgium

PostPosted: Wed Dec 09, 2009 11:37 pm    Post subject:
Reply with quote

Very simple, use the C2D(value) (He asked for it icon_lol.gif )
Back to top
View user's profile Send private message
PeD

Active User


Joined: 26 Nov 2005
Posts: 456
Location: Belgium

PostPosted: Thu Dec 10, 2009 12:03 am    Post subject:
Reply with quote

Quote:
I have got some values in exponential form

What is the internal representation of an exponential form????
For me, exponential form is 8³ or 7² .... and how can you store that format inside a field ?

Maybe I am wrong !!
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Thu Dec 10, 2009 12:08 am    Post subject: Reply to: REXX Function to Change exponential to decimal
Reply with quote

wild guess... floating point icon_question.gif
Back to top
View user's profile Send private message
wlblaney

New User


Joined: 07 Nov 2009
Posts: 3
Location: Frederick, MD

PostPosted: Sat Dec 19, 2009 12:17 am    Post subject: Reply to: REXX Function to Change exponential to decimal
Reply with quote

Try using the following routine as a starting point. It will take a floating point number in internal format and translate it itno a human-readable form. You can use the exponent value to determine where to move the decimal point in the mantissa to get a standard decimal number.

Code:
xlate_float: procedure                                                 
/**********************************************************************/
/*** This routine receives as input a string containing a floating  ***/
/*** point number in internal (HPF) format and returns a character  ***/
/*** string containing the number in standard notation (0.nnnne99). ***/
/*** The fractional decimal portion of the numeric string returned  ***/
/*** will vary depending on the size of the input float variable    ***/
/*** and the number of significant digits (that is, right-most non- ***/
/*** zero digit).  The value may or may not be negative, and the    ***/
/*** exponent may or may not be negative as well.                   ***/
/**********************************************************************/
   parse arg floatin                                                   
   current_precision = digits()                                         
   numeric digits 12                                                   
   log16      = 1.2041199826559                                         
   fracten.0  = 12                                                     
   fracten.1  = 1.2589254117941                                         
   fracten.2  = 1.0232929922807                                         
   fracten.3  = 1.0023052380778                                         
   fracten.4  = 1.0002302850208                                         
   fracten.5  = 1.0000230261160                                         
   fracten.6  = 1.0000023025877                                         
   fracten.7  = 1.0000002302585                                         
    fracten.8  = 1.0000000230258                                         
    fracten.9  = 1.0000000023025                                         
    fracten.10 = 1.0000000002302                                         
    fracten.11 = 1.0000000000230                                         
    fracten.12 = 1.0000000000023                                         
    floatout = 0                                                         
    /*******************************************************************/
    /***  The internal format of a floating-point number is:         ***/
    /***     sppp pppp mmmm mmmm mmmm mmmm mmmm mmmm ...             ***/
    /***  where:                                                     ***/
    /***     s         is the sign bit (0 = positive, 1 = negative); ***/
    /***     ppp pppp  is the exponent in "excess-64 notation (i.e,  ***/
    /***               determine the characteristic by subtracting   ***/
    /***               64 from the value);                           ***/
    /***     mmmm      is 6 or more hex digits that comprise the     ***/
    /***               mantissa.  Increasing the size of a floating  ***/
    /***               point number increases the accuracy of the    ***/
    /***               value, but does not increase the range of     ***/
    /***               possible values.                              ***/
    /*******************************************************************/
    /*******************************************************************/
    /***  Step 1: Convert the internal format to a hex string:       ***/
    /*******************************************************************/
   hex_string = c2x(floatin)                                           
   parse var hex_string exponent 3 mantissa                             
   /*******************************************************************/
   /***  Step 2: Get the sign bit:                                  ***/
   /*******************************************************************/
   sign_bit = substr(x2b(exponent),1,1)                                 
   if sign_bit = 0 then,                                               
      sign_char = " "                                                   
   else                                                                 
      sign_char = "-"                                                   
   /*******************************************************************/
   /***  Step 3: Determine the exponent:                            ***/
   /*******************************************************************/
   exp16 = x2d(b2x("0"substr(x2b(exponent),2))) - 64                   
   exp10 = exp16 * log16                                               
   parse var exp10 expout "." expfrac                                   
   if expout < 0 then                                                   
      expsign = "-"                                                     
   else                                                                 
      expsign = "+"                                                     
   /*******************************************************************/
   /***  Step 4: Determine the mantissa:                            ***/
   /*******************************************************************/
   mantissa = strip(mantissa,'T','0')                                   
   mantsize = length(mantissa)                                         
   mantissa = x2d(mantissa) / 16 ** mantsize                           
   fracadd = 1                                                         
   do p = 1 to fracten.0                                               
      thispos = substr(expfrac,p,1)                                     
      if thispos > 0 then,                                             
         fracadd = fracadd * fracten.p ** thispos                       
   end /* do p = 1 to fracten.0 */                                     
   if expsign = "+" then,                                               
      mantout = mantissa * fracadd                                     
   else                                                                 
      mantout = mantissa / fracadd                                     
   /*******************************************************************/
   /***  Step 5: Step the components together in a readable format: ***/
   /*******************************************************************/
   numeric digits current_precision                                     
   mantout = mantout + 0                                               
   floatout = sign_char || mantout * 10 ** expout                       
return floatout

Code'd
Back to top
View user's profile Send private message
MBabu

Active User


Joined: 03 Aug 2008
Posts: 401
Location: Mumbai

PostPosted: Sat Dec 19, 2009 10:00 pm    Post subject:
Reply with quote

if by 'exponential form' you simply mean the number is showing like 3.14159E12, then see the NUMERIC DIGITS statement
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Sat Dec 19, 2009 10:30 pm    Post subject: Reply to: REXX Function to Change exponential to decimal
Reply with quote

i do not really see why we should waste time for somebody who posts and afterwards,
after having been asked, does not care to answer and provide more info icon_evil.gif
Back to top
View user's profile Send private message
wlblaney

New User


Joined: 07 Nov 2009
Posts: 3
Location: Frederick, MD

PostPosted: Sat Dec 19, 2009 11:35 pm    Post subject: Reply to: REXX Function to Change exponential to decimal
Reply with quote

Enrico,

While the twit^h^h^h^h colleague who originally posed the question may not deserve any help, there will be many others who might also be interested in a solution. Since I had already solved this very problem, it cost me very little effort to post this.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Sun Dec 20, 2009 12:23 am    Post subject: Reply to: REXX Function to Change exponential to decimal
Reply with quote

thanks for the code Bill !

my rant was not specific to this post,
just a general consideration about careless badmannered bahavior
Back to top
View user's profile Send private message
prino

Active Member


Joined: 07 Feb 2009
Posts: 982
Location: Oostende, Belgium

PostPosted: Sun Dec 20, 2009 2:49 am    Post subject:
Reply with quote

Here's some more code that might be useful:

Code:
/* This REXX exec computes a S/370 floating-point's value ...         
   e.g. X'C1280000' represents -2.5                                   
                                  (Michel Castelein, 5 November 1997)*/
                                                                       
say 'Enter the S/370 floating-point (4, 8, or 16 bytes):'             
numeric digits 34                                                     
pull float                                                             
                                                                       
float = X2C(float)           /* convert float to a hexadecimal string*/
float_size = LENGTH(float)                           /* size in Bytes*/
                                                                       
Byte_0 = SUBSTR(float, 1, 1)                                           
select                                                                 
  when BITAND(Byte_0, '80'x) == '00'x then sign = '+'                 
  when BITAND(Byte_0, '80'x) == '80'x then sign = '-'                 
end                                                                   
                                                                       
exponent = C2D(BITAND(Byte_0, '7F'x)) - 64                             
fraction = 0                                                           
power    = -1                                                         
                                                                       
do i = 2 to float_size                                                 
   if i = 9 then iterate                           /* skip bits 64-71*/
   Next_Byte   = C2D(SUBSTR(float, i, 1))                             
   left_Digit  = Next_Byte % 16                                       
   fraction    = fraction + left_Digit * 16**power                     
   right_Digit = Next_Byte // 16                                       
   power       = power - 1                                             
   fraction    = fraction + right_Digit * 16**power                   
   power       = power - 1                                             
end                                                                   
interpret 'value =' sign ( fraction * 16 ** exponent )                 
say "The floating-point's value is" value                             
exit
Back to top
View user's profile Send private message
wlblaney

New User


Joined: 07 Nov 2009
Posts: 3
Location: Frederick, MD

PostPosted: Sun Dec 20, 2009 6:35 am    Post subject: Too Cool!
Reply with quote

Robert,

I really like your solution. I didn't think to try using a negative exponent in REXX.

Very elegant.
Back to top
View user's profile Send private message
prino

Active Member


Joined: 07 Feb 2009
Posts: 982
Location: Oostende, Belgium

PostPosted: Sun Dec 20, 2009 12:49 pm    Post subject: Re: Too Cool!
Reply with quote

wlblaney wrote:
I really like your solution. I didn't think to try using a negative exponent in REXX.

Very elegant.


It's not mine, but was given to me by Michel Castelein. What I really would like to have is a function that does the inverse, convert a floating point number to an S370 floating point, to finalize my formatted edit function.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts What is the command to check MODE of ... rohanthengal CLIST & REXX 6 Fri Nov 18, 2016 1:48 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
This topic is locked: you cannot edit posts or make replies. Rexx to create GDG by scanning JJ result krish.deepu CLIST & REXX 5 Tue Oct 25, 2016 5:32 pm
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us