Print this page




  41 
  42 #include "libm.h"       /* for isgreaterequal macro */
  43 #include <fenv.h>
  44 
  45 double
  46 __fmax(double x, double y) {
  47         union {
  48                 unsigned i[2];
  49                 double d;
  50         } xx, yy;
  51         unsigned s;
  52 
  53         /* if y is nan, replace it by x */
  54         if (y != y)
  55                 y = x;
  56 
  57         /* if x is nan, replace it by y */
  58         if (x != x)
  59                 x = y;
  60 
  61         /* if x is less than y or x and y are unordered, replace x by y */
  62 #if defined(COMPARISON_MACRO_BUG)
  63         if (x < y)
  64 #else
  65         if (!isgreaterequal(x, y))
  66 #endif
  67                 x = y;
  68 
  69         /*
  70          * now x and y are either both NaN or both numeric; clear the
  71          * sign of the result if either x or y has its sign clear
  72          */
  73         xx.d = x;
  74         yy.d = y;
  75 #if defined(__sparc)
  76         s = ~(xx.i[0] & yy.i[0]) & 0x80000000;
  77         xx.i[0] &= ~s;
  78 #elif defined(__x86)
  79         s = ~(xx.i[1] & yy.i[1]) & 0x80000000;
  80         xx.i[1] &= ~s;
  81 #else
  82 #error Unknown architecture
  83 #endif
  84 
  85         return (xx.d);
  86 }


  41 
  42 #include "libm.h"       /* for isgreaterequal macro */
  43 #include <fenv.h>
  44 
  45 double
  46 __fmax(double x, double y) {
  47         union {
  48                 unsigned i[2];
  49                 double d;
  50         } xx, yy;
  51         unsigned s;
  52 
  53         /* if y is nan, replace it by x */
  54         if (y != y)
  55                 y = x;
  56 
  57         /* if x is nan, replace it by y */
  58         if (x != x)
  59                 x = y;
  60 
  61         /* At this point, x and y are either both numeric, or both NaN */
  62         if (!isnan(x) && !isgreaterequal(x, y))




  63                 x = y;
  64 
  65         /*
  66          * clear the sign of the result if either x or y has its sign clear

  67          */
  68         xx.d = x;
  69         yy.d = y;
  70 #if defined(__sparc)
  71         s = ~(xx.i[0] & yy.i[0]) & 0x80000000;
  72         xx.i[0] &= ~s;
  73 #elif defined(__x86)
  74         s = ~(xx.i[1] & yy.i[1]) & 0x80000000;
  75         xx.i[1] &= ~s;
  76 #else
  77 #error Unknown architecture
  78 #endif
  79 
  80         return (xx.d);
  81 }