4

Code fragment in PL/I is given below:

DECLARE WAVE_LTH FLOAT BINARY(21);

...

WAVE_LTH = 11001E-10B (**resultant value = 0.0244140**)

Can anybody clarify how the resultant value is derived?

piet.t
  • 11,718
  • 21
  • 43
  • 52
  • 5
    I am not familiar with the notation (is this PL/1?) but the value seems to be 25 * 2**(-10) = 24 / 1024 = 0.02441406. 11001 in binary is 25 in decimal, the exponent is given in decimal, so -10. The trailing "B" presumably tells us that the base is binary. – njuffa Sep 02 '15 at 06:46
  • Looks like PL1 (or a derivative), I think njuffa analysis is correct. Float Binary(21) declares a 21 bit accuracy binary floating point number. In this case they are using base-2 assignment – Bruce Martin Sep 02 '15 at 08:57
  • 2
    @njufa: I think you should post this as answer. – Rudy Velthuis Sep 02 '15 at 09:59

1 Answers1

9

The program statement in question is presumably from a PL/I program running on IBM System/360 hardware. This used a hexadecimal floating-point representation, for details see this Wikipedia article.

According to my old literature on PL/I, FLOAT BINARY(21) specifies a single-precision floating-point number on this platform. 21 specifies the effective number of mantissa bits. As this corresponds to the default value for a FLOAT BINARY operand, it could be left off. Due to the base-16 representation the most significant three bits of the 24-bit mantissa could be zero; this leaves a guaranteed 21 bits of precision.

The B suffix tells us that the floating-point literal uses base-2 representation. 11001 in binary is 25 in decimal. The exponent itself is given in decimal, so E-10 means the scale factor is 2-10. The value of this floating-point literal constant is therefore 25 / 1024 or 0.0244140.

njuffa
  • 23,970
  • 4
  • 78
  • 130
  • Good answer. I was considering voting to close as a typo (read the manual for me) but when I checked it is not so clear in the manual :-) PL/1 = PL/I. Came as news to me a few years ago, but proved to be true. If someone is concerned today, it is now running on a z/Architechture system, no-one has used a 360 for at least 30 years. This is the latest Mainframe announcement, http://www-03.ibm.com/systems/z/announcement.html, and this, where Enterprise PL/I 4.2 will run is http://www-03.ibm.com/systems/z/hardware/z13.html – Bill Woodger Sep 02 '15 at 18:00
  • @BillWoodger Thanks for pointing out that it should be "PL/I", not "PL/1", I will fix that in my answer. I actually have never used PL/I (and used a IBM system /360 compatible machine only for a few months, a long time ago), but do have some awareness from books. – njuffa Sep 02 '15 at 18:09
  • Well, that makes you answer even better :-) – Bill Woodger Sep 02 '15 at 18:12