scalb and ldexp

Fred Tydeman uunet!ibminet.awdpa.ibm.com!ibmpa!tydeman
Wed Sep 23 08:16:43 PDT 1992


Additional comment on Floating-Point C Extensions (X3J11.1/92-040).
 
Two functions with similar jobs have dissimilar headers.
 
double ldexp( double x, int exp);
double scalb( double x, long int exp);
 
ldexp computes x * 2**exp
 
scalb computes x * FLT_RADIX**exp, where FLT_RADIX is most likely one of
2, 8, 10, or 16.
 
Since the base used in scalb is never smaller than 2, the base used in
ldexp, it seems logical that the power (exp) will never be larger than
the power used in ldexp (unless overflow or underflow will happen).
 
Hence, it appears that exp should have the same type to both functions.
 
Now, is int big enough?
 
For most micros, where int is often only 16-bits, IEEE-754 floating
point is used.  The exponent range of IEEE-754 double is -1021 to +1024,
so a 16-bit int is large enough.
 
On the other hand, there are computers where the exponent range can
go as low as -32896 (Prime 50 Series) and as large as +32780 (Unisys
"A Series").  But on those machines, I believe int is typically 32-bits,
so again, int is large enough.
 
Should scalb be changed from long int to int?
 
Note:  The exponent ranges came from Annex F (Typical Floating Point
Formats) from LIA Part 1:  Integer and floating-point arithmetic.
 
These are not IBM's views, these are the personal ones of:
Fred Tydeman, IBM, Austin, Texas (512) 838-3322; fax (512) 838-3484
AIX S/6000 Math library architect & IBM's rep to NCEG (X3J11.1)
Internet: tydemanaibmpa.awdpa.ibm.com    uucp: uunet!ibmsupt!tydeman



More information about the Numeric-interest mailing list