home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / pmlsrc23.zoo / envtests / testmodf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-19  |  1.9 KB  |  60 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *                N O T I C E                *
  4.  *                                    *
  5.  *            Copyright Abandoned, 1987, Fred Fish        *
  6.  *                                    *
  7.  *    This previously copyrighted work has been placed into the    *
  8.  *    public domain by the author (Fred Fish) and may be freely used    *
  9.  *    for any purpose, private or commercial.  I would appreciate    *
  10.  *    it, as a courtesy, if this notice is left in all copies and    *
  11.  *    derivative works.  Thank you, and enjoy...            *
  12.  *                                    *
  13.  *    The author makes no warranty of any kind with respect to this    *
  14.  *    product and explicitly disclaims any implied warranties of    *
  15.  *    merchantability or fitness for any particular purpose.        *
  16.  *                                    *
  17.  ************************************************************************
  18.  */
  19.  
  20.  
  21. /*
  22.  *  FILE
  23.  *
  24.  *    testmodf.c    test the runtime environment function modf
  25.  *
  26.  *    This simple minded program is provided to aid in testing
  27.  *    the "modf" function assumed to be provided in the runtime
  28.  *    environment.  If not provided, a suitable substitute can
  29.  *    be coded in C, however the necessary code is very machine
  30.  *    dependent and is generally almost trivial to code in assembly
  31.  *    language for the specific host machine.
  32.  *
  33.  *    The modf() function takes two arguments.  The first is a double value
  34.  *    and the second is a pointer to a double.  Modf() returns the
  35.  *    signed fraction part of the first argument, and stores the integral
  36.  *    part (as a double) indirectly in the location pointed to by the
  37.  *    second argument.  Note that both the direct and indirect result will
  38.  *    have the same sign, and:
  39.  *
  40.  *        <integral part> + <fractional part> = <original value>
  41.  *
  42.  *    See "frexp(3C)" in the Unix System V User's Manual for more
  43.  *    information.
  44.  *
  45.  */
  46.  
  47. extern double modf ();
  48.  
  49. main ()
  50. {
  51.     double input;            /* Input value */
  52.     double frac;
  53.     double ipart;
  54.     
  55.     while (scanf ("%le", &input) == 1) {
  56.     frac = modf (input, &ipart);
  57.     printf ("%le %le\n", frac, ipart);
  58.     }
  59. }
  60.