Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
Soundammal.S

New User

Joined: 05 May 2008
Posts: 29
Location: Chennai

 Posted: Wed Dec 09, 2009 3:01 pm    Post subject: REXX Function to Change exponential to decimal 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.

expat

Global Moderator

Joined: 14 Mar 2007
Posts: 8794
Location: Welsh Wales

 Posted: Wed Dec 09, 2009 3:05 pm    Post subject: What have you researched for yourself and what problems did you encounter ?
dbzTHEdinosauer

Global Moderator

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

Posted: Wed Dec 09, 2009 6:33 pm    Post subject:

 Soundammal.S wrote: values in exponential form

I am just a dumb old programmer, could you please explain what you mean by exponential form
dick scherrer

Site Director

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

 Posted: Wed Dec 09, 2009 10:04 pm    Post subject: 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. . .
PeterHolland

Global Moderator

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

 Posted: Wed Dec 09, 2009 10:20 pm    Post subject: Or post "what you have not"?
prino

Senior Member

Joined: 07 Feb 2009
Posts: 1194
Location: Vilnius, Lithuania

 Posted: Wed Dec 09, 2009 11:37 pm    Post subject: Very simple, use the C2D(value) (He asked for it )
PeD

Active User

Joined: 26 Nov 2005
Posts: 458
Location: Belgium

Posted: Thu Dec 10, 2009 12:03 am    Post subject:

 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 !!
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10682
Location: italy

 Posted: Thu Dec 10, 2009 12:08 am    Post subject: Reply to: REXX Function to Change exponential to decimal wild guess... floating point
wlblaney

New User

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

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

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
MBabu

Active User

Joined: 03 Aug 2008
Posts: 401
Location: Mumbai

 Posted: Sat Dec 19, 2009 10:00 pm    Post subject: if by 'exponential form' you simply mean the number is showing like 3.14159E12, then see the NUMERIC DIGITS statement
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10682
Location: italy

 Posted: Sat Dec 19, 2009 10:30 pm    Post subject: Reply to: REXX Function to Change exponential to decimal 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
wlblaney

New User

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

 Posted: Sat Dec 19, 2009 11:35 pm    Post subject: Reply to: REXX Function to Change exponential to decimal 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.
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10682
Location: italy

 Posted: Sun Dec 20, 2009 12:23 am    Post subject: Reply to: REXX Function to Change exponential to decimal thanks for the code Bill ! my rant was not specific to this post, just a general consideration about careless badmannered bahavior
prino

Senior Member

Joined: 07 Feb 2009
Posts: 1194
Location: Vilnius, Lithuania

Posted: Sun Dec 20, 2009 2:49 am    Post subject:

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
wlblaney

New User

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

 Posted: Sun Dec 20, 2009 6:35 am    Post subject: Too Cool! Robert, I really like your solution. I didn't think to try using a negative exponent in REXX. Very elegant.
prino

Senior Member

Joined: 07 Feb 2009
Posts: 1194
Location: Vilnius, Lithuania

Posted: Sun Dec 20, 2009 12:49 pm    Post subject: Re: Too Cool!

 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.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Compare multiple files using JCL/Rexx... tanvi110788 JCL & VSAM 4 Tue May 19, 2020 5:47 pm In JCL Procedure how we can execute R... Dhananjayulu Neeli CLIST & REXX 7 Sat May 16, 2020 12:01 am Calling a Rexx from within another Rexx ManuelPacheco CLIST & REXX 3 Wed Apr 22, 2020 2:45 pm Naming a newly opened screen using REXX Ben12345 CLIST & REXX 2 Fri Apr 17, 2020 5:48 am Macro REXX - ISRE741 Command not exec... sandeep prajapati CLIST & REXX 1 Fri Apr 17, 2020 12:48 am

 © 2003-2020 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us