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 / pmlsrc / dabs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-19  |  2.1 KB  |  121 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.  *  FUNCTION
  23.  *
  24.  *    dabs,fabs   double precision absolute value
  25.  *
  26.  *  KEY WORDS
  27.  *
  28.  *    dabs
  29.  *    fabs
  30.  *    machine independent routines
  31.  *    math libraries
  32.  *
  33.  *  DESCRIPTION
  34.  *
  35.  *    Returns absolute value of double precision number.
  36.  *
  37.  *    The fabs routine is supplied for compatibility with unix
  38.  *    libraries where for some bizarre reason, the double precision
  39.  *    absolute value routine is called fabs.
  40.  *
  41.  *  USAGE
  42.  *
  43.  *    double dabs (x)
  44.  *    double x;
  45.  *
  46.  *    double fabs (x)
  47.  *    double x;
  48.  * 
  49.  *  PROGRAMMER
  50.  *
  51.  *    Fred Fish
  52.  *
  53.  */
  54. #if !defined (OLD)    /* mjr++    */
  55.  
  56. __asm("
  57. .text
  58. .even
  59. .globl _dabs
  60. .globl _fabs
  61.  
  62. _dabs:
  63. _fabs:
  64.     moveml    a7@(4),d0-d1
  65.     bclr    #31,d0
  66.     rts
  67. ");
  68.  
  69. #else OLD
  70.  
  71. #include <stdio.h>
  72. #include <math.h>
  73. #include "pml.h"
  74.  
  75. #ifdef IEEE
  76. struct bitdouble {
  77.     unsigned long sign : 1;
  78.     unsigned long exp  : 11;
  79.     unsigned long mant1: 20;
  80.     unsigned long mant2: 32;
  81. };
  82. #endif
  83.  
  84.  
  85. #if defined(m68k) && defined(__GNUC__)
  86. asm(".stabs \"_fabs\",5,0,0,_dabs"); /* dept of clean tricks */
  87. #endif
  88.  
  89. double dabs (x)
  90. double x;
  91. {
  92. #ifndef IEEE
  93.     if (x < 0.0) {
  94.     x = -x;
  95.     }
  96.     return (x);
  97. #else
  98.     struct bitdouble *bd = (struct bitdouble *)&x;
  99.     bd->sign = 0;
  100.  
  101.     return x;
  102. #endif
  103. }
  104.  
  105. #if !(defined(m68k) && defined(__GNUC__))
  106. double fabs (x)
  107. double x;
  108. {
  109. #ifndef IEEE
  110.     return (dabs(x));
  111. #else
  112.     struct bitdouble *bd = (struct bitdouble *)&x;
  113.     bd->sign = 0;
  114.  
  115.     return x;
  116. #endif
  117. }
  118. #endif
  119.  
  120. #endif OLD
  121.