home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sa104os2.zip / SATHR104.ZIP / SATHER / SYSTEM / FLTD.C < prev    next >
C/C++ Source or Header  |  1994-12-22  |  1KB  |  57 lines

  1. #include "header.h"
  2. #include <string.h>
  3.  
  4. FLTD c_fltd_aset(FLTD f, INT bit, BOOL val)
  5. {
  6.     sbi_aset(&f, bit, val, 64);
  7.     return f;
  8. }
  9.  
  10. BOOL c_fltd_aget(FLTD f, INT bit)
  11. {
  12.     return sbi_aget(&f, bit, 64);
  13. }
  14.  
  15. INT c_fltd_int(FLTD d) {
  16.     return (INT) d;
  17. }
  18.  
  19. int c_fltd_str_in(FLTD f, char* store_in) {
  20.   /*  Store the floating point value f in the string store_in */
  21.   /* store_in must have the maximum storage that may be needed?
  22.      Return the actual length of store_in */
  23.   sprintf(store_in,"%g",f);
  24.   return(strlen(store_in));
  25. }
  26.  
  27. int c_fltd_str_in_prec(FLTD f, char* store_in, INT precision) {
  28.   /*  Store the floating point value f in the string store_in with 
  29.     precision = "precision". Return the used length of store_in*/
  30.   /* store_in must have the maximum storage that may be needed? */
  31.   char buf[20];
  32.   sprintf(buf,"%%.%dg",precision);
  33.   sprintf(store_in,buf,f);
  34.   return(strlen(store_in));
  35. }
  36.  
  37. #if defined(_AIX) || defined(SUNOS5) || defined(__NeXT__)
  38. FLTD exp10(FLTD f) {
  39.    return pow(10.0, f);
  40. }
  41. #endif
  42.  
  43. #if defined(__hpux) || defined(SCO)
  44. /* This is just a quick hack - real rint does something better
  45.    for rounding - somebody send me a correct version. */
  46.  
  47. double rint(double x)
  48. {
  49.   double tmp = floor(x);
  50.  
  51.   if (fabs(x - tmp) < 0.5)
  52.     return tmp;
  53.   else
  54.     return tmp + 1;
  55. }
  56. #endif
  57.