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

REXX Function to Change exponential to decimal


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
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
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: 8797
Location: Welsh Wales

PostPosted: Wed Dec 09, 2009 3:05 pm
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
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

Moderator Emeritus


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

PostPosted: Wed Dec 09, 2009 10:04 pm
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: 2481
Location: Netherlands, Amstelveen

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

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

Senior Member


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

PostPosted: Wed Dec 09, 2009 11:37 pm
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: 459
Location: Belgium

PostPosted: Thu Dec 10, 2009 12:03 am
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Dec 10, 2009 12:08 am
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
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: 400
Location: Mumbai

PostPosted: Sat Dec 19, 2009 10:00 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Dec 19, 2009 10:30 pm
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sun Dec 20, 2009 12:23 am
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

Senior Member


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

PostPosted: Sun Dec 20, 2009 2:49 am
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
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

Senior Member


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

PostPosted: Sun Dec 20, 2009 12:49 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Compile Several JCL JOB Through one r... CLIST & REXX 4
No new posts Running REXX through JOB CLIST & REXX 13
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts isfline didnt work in rexx at z/OS ve... CLIST & REXX 7
Search our Forums:

Back to Top