Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1.  
  2. /* @(#)w_fmod.c 5.1 93/09/24 */
  3. /*
  4.  * ====================================================
  5.  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  6.  *
  7.  * Developed at SunPro, a Sun Microsystems, Inc. business.
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software is freely granted, provided that this notice
  10.  * is preserved.
  11.  * ====================================================
  12.  */
  13.  
  14. /*
  15. FUNCTION
  16. <<fmod>>, <<fmodf>>---floating-point remainder (modulo)
  17.  
  18. INDEX
  19. fmod
  20. INDEX
  21. fmodf
  22.  
  23. ANSI_SYNOPSIS
  24. #include <math.h>
  25. double fmod(double <[x]>, double <[y]>)
  26. float fmodf(float <[x]>, float <[y]>)
  27.  
  28. TRAD_SYNOPSIS
  29. #include <math.h>
  30. double fmod(<[x]>, <[y]>)
  31. double (<[x]>, <[y]>);
  32.  
  33. float fmodf(<[x]>, <[y]>)
  34. float (<[x]>, <[y]>);
  35.  
  36. DESCRIPTION
  37. The <<fmod>> and <<fmodf>> functions compute the floating-point
  38. remainder of <[x]>/<[y]> (<[x]> modulo <[y]>).
  39.  
  40. RETURNS
  41. The <<fmod>> function returns the value
  42. @ifnottex
  43. <[x]>-<[i]>*<[y]>,
  44. @end ifnottex
  45. @tex
  46. $x-i\times y$,
  47. @end tex
  48. for the largest integer <[i]> such that, if <[y]> is nonzero, the
  49. result has the same sign as <[x]> and magnitude less than the
  50. magnitude of <[y]>.
  51.  
  52. <<fmod(<[x]>,0)>> returns NaN, and sets <<errno>> to <<EDOM>>.
  53.  
  54. You can modify error treatment for these functions using <<matherr>>.
  55.  
  56. PORTABILITY
  57. <<fmod>> is ANSI C. <<fmodf>> is an extension.
  58. */
  59.  
  60. /*
  61.  * wrapper fmod(x,y)
  62.  */
  63.  
  64. #include "fdlibm.h"
  65. #include <errno.h>
  66.  
  67. #ifndef _DOUBLE_IS_32BITS
  68.  
  69. #ifdef __STDC__
  70.         double fmod(double x, double y) /* wrapper fmod */
  71. #else
  72.         double fmod(x,y)                /* wrapper fmod */
  73.         double x,y;
  74. #endif
  75. {
  76. #ifdef _IEEE_LIBM
  77.         return __ieee754_fmod(x,y);
  78. #else
  79.         double z;
  80.         struct exception exc;
  81.         z = __ieee754_fmod(x,y);
  82.         if(_LIB_VERSION == _IEEE_ ||isnan(y)||isnan(x)) return z;
  83.         if(y==0.0) {
  84.             /* fmod(x,0) */
  85.             exc.type = DOMAIN;
  86.             exc.name = "fmod";
  87.             exc.arg1 = x;
  88.             exc.arg2 = y;
  89.             exc.err = 0;
  90.             if (_LIB_VERSION == _SVID_)
  91.                exc.retval = x;
  92.             else
  93.                exc.retval = 0.0/0.0;
  94.             if (_LIB_VERSION == _POSIX_)
  95.                errno = EDOM;
  96.             else if (!matherr(&exc)) {
  97.                   errno = EDOM;
  98.             }
  99.             if (exc.err != 0)
  100.                errno = exc.err;
  101.             return exc.retval;
  102.         } else
  103.             return z;
  104. #endif
  105. }
  106.  
  107. #endif /* defined(_DOUBLE_IS_32BITS) */
  108.