ack/lang/cem/libcc.ansi/math/ldexp.c

37 lines
595 B
C
Raw Normal View History

1989-05-10 16:08:14 +00:00
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <math.h>
double
ldexp(double fl, int exp)
{
int sign = 1;
int currexp;
if (fl<0) {
fl = -fl;
sign = -1;
}
fl = frexp(fl,&currexp);
exp += currexp;
if (exp > 0) {
while (exp>30) {
fl *= (double) (1L << 30);
exp -= 30;
}
fl *= (double) (1L << exp);
}
else {
while (exp<-30) {
fl /= (double) (1L << 30);
exp += 30;
}
fl /= (double) (1L << -exp);
}
return sign * fl;
}