× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Entry Parameters
  • From: "Simon Coulter" <shc@xxxxxxxxxxxxxxxxx>
  • Date: Fri, 28 Jan 00 10:15:50 +1100


Hello Barbara,

I know you know this stuff.  I wouldn't teach my Granny about eggs and I doubt 
I need to teach 
you about numeric representation.  The "homework" was for any interested others 
-- besides, 
confusing the issue is half the fun :).  Now as to the challenge:

Do you want this in S/370 format, VAX format, IEEE-754 format, or one of the 
countless other 
compiler and platform specific floating-point representations?  Let's assume 
IEEE since that is 
the format used by our favourite machine and most platforms and compilers are 
using it too.

I am not sure about this being within the capabilities of the "ordinary" user 
but it is 
certainly within the capabilities of any programmer.

Floating-point numbers are written in the form mantissa base exponent.  
So-called scientific 
notation uses a base of 10 but computers use a base of 2 (or sometimes 16).  A 
single-precision 
floating point number occupies 4 bytes, a double takes 8 bytes.  Lets stick 
with 4-byte floats.

IEEE says that a 4-byte float has 1 bit for the sign, then 8 bits for the 
exponent, then 23 
bits for the mantissa.  So for any given number we need to determine three 
parts.  The sign is 
easy:  if the number is positive the sign is 0, if negative the sign is 1.

The mantissa isn't too hard either.  Convert the number to binary and normalise 
it.  So for the 
number 5 we get 101 in binary (which can be thought of as 101.0).  Normalising 
that gives us 
1.01 and we remove the leading one (a normalised binary number will always have 
a leading 1 so 
its presence is implicit).  The mantissa value is 01.

The exponent is a little trickier.  A bias value is used to determine whether 
the exponent 
represents a positive value indicating a shift to the right or a negative value 
indicating a 
shift to the left.  The bias for IEEE is 127 for 4-byte floats.  Normalising 
caused the decimal 
point to move 2 positions to the left so the exponent is 2 (10 in binary).  We 
must add the 
bias to the exponent so we get 129 which is 10000001.

Now that we have the pieces lets assemble them.  Sign is 0, exponent is 
10000001, mantissa is 
01, therefore the IEEE floating-point binary representation of decimal 5 is 
01000000101.

Now we need to convert that binary number to hex, and ensure it is 4 bytes, to 
pass it in from 
the command line.  Doing so gives us X'40A00000'.  This process takes much 
longer to explain 
than to actually perform.

        CALL PGM(TSTFLOAT) PARM(X'40A00000')

0 = X'00000000'
1 = X'3F800000'
2 = X'40000000'
3 = X'40400000'
4 = X'40800000'
5 = X'40A00000'
6 = X'40C00000'
7 = X'40E00000'
8 = X'41000000'
9 = X'41100000'
10 = X'41200000'

70.457 = X'428CE9FC'

I leave it has homework for those interested to handle decimal fractions.

If you have an easier way I'd certainly be interested in knowing it.

Regards,
Simon Coulter.

«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
«» FlyByNight Software         AS/400 Technical Specialists       «»
«» Eclipse the competition - run your business on an IBM AS/400.  «»
«»                                                                «»
«» Phone: +61 3 9419 0175      Mobile: +61 0411 091 400           «»
«» Fax:   +61 3 9419 0175      mailto: shc@flybynight.com.au      «»
«»                                                                «»
«» Windoze should not be open at Warp speed.                      «»
«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
//--- forwarded letter -------------------------------------------------------
> Date: Thu, 20 Jan 2000 16:16:00 -0500
> From: bmorris@ca.ibm.com
> To: RPG400-L@midrange.com
> Reply-To: RPG400-L@midrange.com
> Subject: Entry Parameters

> 
> >Date: Thu, 20 Jan 00 19:32:20 +1100
> >From: "Simon Coulter" <shc@flybynight.com.au>
> >
> >Negative values aren't a problem either.
> >
> >   CALL PGM(JIMCONEX/CHGAPOPEN) PARM('5J' '99011}' '5J' '00012}')
> >
> >will pass all the values as negative numbers.
> 
> Well, duh.  Yeah, I knew that.  But that's
ven worse than coding
> x'00123D' for packed.  Anyway, I didn't want to confuse the issue.
> 
> >Homework: "Why is it so?"
> 
> Ah done finished mah homework ages ago.
> 
> Here's homework for you: how to pass a float parameter from the command
> line.
> (Describe a method for the "ordinary" user, no more difficult than the
> method
> for passing negative zoned numbers that you sort of described above.)
> Heehee.
> 
> (Actually, I agree with you that all programmers should understand the
> layout
> of numeric values of every type.)
> 
> Barbara

+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.