|
|
1.1 ! root 1: /* ! 2: * "@(#)cabs.c 1.1" ! 3: */ ! 4: /* ! 5: * THIS IS STRONGLY BASED ON THE TAHOE FLOATING POINT REPRESENTATION! ! 6: * The casts are meant to speed things up by avoiding double precision ! 7: * instructions. ! 8: */ ! 9: ! 10: #include <FP.h> ! 11: ! 12: float cabs(real, imag) ! 13: float real, imag; ! 14: { ! 15: float temp; ! 16: fortran float sqrt(); ! 17: ! 18: if(real < 0) ! 19: ((sp_format *)&real)->sign = 0; /* real = -real; */ ! 20: if(imag < 0) ! 21: ((sp_format *)&imag)->sign = 0; /* imag = -imag; */ ! 22: if(imag > real){ ! 23: temp = *(float *)ℜ ! 24: *(float *)&real = *(float *)&imag; ! 25: *(float *)&imag = temp; ! 26: } ! 27: if(*(float *)&imag == 0) /* originally if((real+imag)==real) ! */ ! 28: return(*(float *)&real); ! 29: ! 30: temp = (*(float *)&imag)/(*(float *)&real); ! 31: temp = (*(float *)&real)*sqrt(1.0 + temp*temp); /*overflow!!*/ ! 32: return(temp); ! 33: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.