Print this page
5224 snprintf rounding under [default] FE_TONEAREST


  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 #include "lint.h"
  30 #include "base_conversion.h"
  31 #include <sys/isa_defs.h>
  32 
  33 #define CSR_DEFAULT 0x1f80
  34 
  35 /* The following should be coded as inline expansion templates.  */
  36 
  37 /*
  38  * Multiplies two normal or subnormal doubles, returns result and exceptions.
  39  */
  40 double
  41 __mul_set(double x, double y, int *pe) {
  42         extern void _putmxcsr(), _getmxcsr();
  43         int csr;
  44         double z;
  45 
  46         _putmxcsr(CSR_DEFAULT);














  47         z = x * y;
  48         _getmxcsr(&csr);
  49         if ((csr & 0x3f) == 0) {
  50                 *pe = 0;
  51         } else {
  52                 /* Result may not be exact. */
  53                 *pe = 1;
  54         }
  55         return (z);
  56 }
  57 
  58 /*
  59  * Divides two normal or subnormal doubles x/y, returns result and exceptions.
  60  */
  61 double
  62 __div_set(double x, double y, int *pe) {
  63         extern void _putmxcsr(), _getmxcsr();
  64         int csr;
  65         double z;
  66 
  67         _putmxcsr(CSR_DEFAULT);

  68         z = x / y;
  69         _getmxcsr(&csr);
  70         if ((csr & 0x3f) == 0) {
  71                 *pe = 0;
  72         } else {
  73                 *pe = 1;
  74         }
  75         return (z);
  76 }
  77 
  78 double
  79 __dabs(double *d)
  80 {
  81         /* should use hardware fabs instruction */
  82         return ((*d < 0.0) ? -*d : *d);
  83 }
  84 
  85 /*
  86  * Returns IEEE mode/status and
  87  * sets up standard environment for base conversion.


  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 #include "lint.h"
  30 #include "base_conversion.h"
  31 #include <sys/isa_defs.h>
  32 
  33 #define CSR_DEFAULT 0x1f80
  34 
  35 /* The following should be coded as inline expansion templates.  */
  36 
  37 /*
  38  * Multiplies two normal or subnormal doubles, returns result and exceptions.
  39  */
  40 double
  41 __mul_set(double x, double y, int *pe) {
  42         extern void _putmxcsr(), _getmxcsr();
  43         int csr;
  44         volatile double z;
  45 
  46         _putmxcsr(CSR_DEFAULT);
  47         /*
  48          * NOTE:  By declaring 'z' volatile above, we intend for the
  49          * compiler to not move this after the _getmxcsr() call, whose results
  50          * are only useful if they immediately follow the multiply.
  51          *
  52          * From the C11 spec:
  53          *
  54          * 134 - A volatile declaration may be used to describe an
  55          * object corresponding to a memory-mapped input/output port
  56          * or an object accessed by an asynchronously interrupting
  57          * function. Actions on objects so declared shall by an
  58          * implementation or reordered except as permitted by the
  59          * rules for evaluating expressions."
  60          */
  61         z = x * y;
  62         _getmxcsr(&csr);
  63         if ((csr & 0x3f) == 0) {
  64                 *pe = 0;
  65         } else {
  66                 /* Result may not be exact. */
  67                 *pe = 1;
  68         }
  69         return (z);
  70 }
  71 
  72 /*
  73  * Divides two normal or subnormal doubles x/y, returns result and exceptions.
  74  */
  75 double
  76 __div_set(double x, double y, int *pe) {
  77         extern void _putmxcsr(), _getmxcsr();
  78         int csr;
  79         volatile double z;
  80 
  81         _putmxcsr(CSR_DEFAULT);
  82         /* NOTE:  See __mul_set() above, same principle applies here. */
  83         z = x / y;
  84         _getmxcsr(&csr);
  85         if ((csr & 0x3f) == 0) {
  86                 *pe = 0;
  87         } else {
  88                 *pe = 1;
  89         }
  90         return (z);
  91 }
  92 
  93 double
  94 __dabs(double *d)
  95 {
  96         /* should use hardware fabs instruction */
  97         return ((*d < 0.0) ? -*d : *d);
  98 }
  99 
 100 /*
 101  * Returns IEEE mode/status and
 102  * sets up standard environment for base conversion.