home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / standard / math.z / math
Encoding:
Text File  |  1998-10-30  |  40.4 KB  |  726 lines

  1.  
  2.  
  3.  
  4. MMMMAAAATTTTHHHH((((3333MMMM))))                                                              MMMMAAAATTTTHHHH((((3333MMMM))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      math - introduction to mathematical library functions
  10.  
  11. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  12.      These functions constitute the C math library _l_i_b_m. There are four
  13.      versions of the math library _l_i_b_m._a, _l_i_b_m_x._a, _l_i_b_m_4_3._a and _l_i_b_f_a_s_t_m._a
  14.  
  15.      The first, _l_i_b_m._a, contains routines newly implemented (1994) using
  16.      algorithms which take advantage of the Mips architecture and includes
  17.      many routines for the _f_l_o_a_t data type.
  18.  
  19.      For the -64 and -n32 versions of _l_i_b_m._a, a second version of the math
  20.      library, _l_i_b_m_x._a, contains functions which give identical results to
  21.      those in libm.a, but which use System V error handling.
  22.      See matherr(3M) for a description of error handling for _l_i_b_m_x._a
  23.      functions.
  24.  
  25.      The third version of the math library, _l_i_b_m_4_3._a, contains routines all
  26.      based on the original codes in the 4.3BSD release.  The difference
  27.      between the error bounds for libm.a and libm43.a is typically around 1
  28.      unit in the last place, whereas the performance difference may be a
  29.      factor of two or more.
  30.  
  31.      The link editor searches this library under the "-lm", "-lmx", or "-lm43"
  32.      option.  Declarations for these functions may be obtained from the
  33.      include file <_m_a_t_h._h>.
  34.  
  35.      The fourth library, _l_i_b_f_a_s_t_m._a, contains faster, lower-precision versions
  36.      of various routines from libm.a.
  37.  
  38. LLLLIIIISSSSTTTT OOOOFFFF FFFFUUUUNNNNCCCCTTTTIIIIOOOONNNNSSSS
  39.      Error bounds listed below apply only to the -64 and -n32 versions of
  40.      _l_i_b_m._a and _l_i_b_m_x._a The error bound sometimes applies only to the primary
  41.      range.
  42.  
  43.  
  44.                                                            _E_r_r_o_r _B_o_u_n_d (_U_L_P_s)
  45.      _N_a_m_e      _A_p_p_e_a_r_s _o_n _P_a_g_e    _D_e_s_c_r_i_p_t_i_o_n                 _l_i_b_m._a _l_i_b_m_4_3._a
  46.      acos        sin(3M)      inverse trigonometric function     2      3
  47.      acosf       sin(3M)      inverse trigonometric function     1
  48.      acosh       asinh(3M)    inverse hyperbolic function        3      3
  49.      asin        sin(3M)      inverse trigonometric function     2      3
  50.      asinf       sin(3M)      inverse trigonometric function     1
  51.      asinh       asinh(3M)    inverse hyperbolic function        3      3
  52.      atan        sin(3M)      inverse trigonometric function    1.5     1
  53.      atanf       sin(3M)      inverse trigonometric function     1
  54.      atanh       asinh(3M)    inverse hyperbolic function        3      3
  55.      atan2       sin(3M)      inverse trigonometric function     2      2
  56.      atan2f      sin(3M)      inverse trigonometric function     1
  57.      cabs        hypot(3M)    complex absolute value             1      1
  58.      cabsf       hypot(3M)    complex absolute value             1
  59.      cbrt        sqrt(3M)     cube root                          1      1
  60.  
  61.  
  62.                                                                         PPPPaaaaggggeeee 1111
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. MMMMAAAATTTTHHHH((((3333MMMM))))                                                              MMMMAAAATTTTHHHH((((3333MMMM))))
  70.  
  71.  
  72.  
  73.      ceil        floor(3M)    integer no less than               0      0
  74.      ceilf       floor(3M)    integer no less than               0      0
  75.      copysign    ieee(3M)     copy sign bit                      0      0
  76.      cos         sin(3M)      trigonometric function             2      1
  77.      cosf        sin(3M)      trigonometric function             1
  78.      cosh        sinh(3M)     hyperbolic function                2      3
  79.      coshf       sinh(3M)     hyperbolic function                1
  80.      drem        ieee(3M)     remainder                          0      0
  81.      erf         erf(3M)      error function                     ?      ?
  82.      erfc        erf(3M)      complementary error function       ?      ?
  83.      exp         exp(3M)      exponential                        1      1
  84.      expf        exp(3M)      exponential                        1
  85.      expm1       exp(3M)      exp(x)-1                           1      1
  86.      expm1f      exp(3M)      exp(x)-1                           1
  87.      fabs        floor(3M)    absolute value                     0      0
  88.      fabsf       floor(3M)    absolute value                     0      0
  89.      finite      ieee(3M)     floating point arithmetic        (N/A)
  90.      floor       floor(3M)    integer no greater than            0      0
  91.      floorf      floor(3M)    integer no greater than            0      0
  92.      fmod        floor(3M)    remainder function                 0
  93.      fmodf       floor(3M)    remainder function                 0
  94.      hypot       hypot(3M)    Euclidean distance                 1      1
  95.      hypotf      hypot(3M)    Euclidean distance                 1      1
  96.      j0          j0(3M)       bessel function                    ?      ?
  97.      j1          j0(3M)       bessel function                    ?      ?
  98.      jn          j0(3M)       bessel function                    ?      ?
  99.      lgamma      lgamma(3M)   log gamma function                 ?      ?
  100.      log         exp(3M)      natural logarithm                  1      1
  101.      logf        exp(3M)      natural logarithm                  1
  102.      logb        ieee(3M)     exponent extraction                0      0
  103.      log10       exp(3M)      logarithm to base 10               2      3
  104.      log10f      exp(3M)      logarithm to base 10              1.5
  105.      log1p       exp(3M)      log(1+x)                           1      1
  106.      log1pf      exp(3M)      log(1+x)                           1      1
  107.      pow         exp(3M)      exponential x**y                   2    60-500
  108.      powf        exp(3M)      exponential x**y                   1
  109.      rint        floor(3M)    round to nearest integer           0      0
  110.      sin         sin(3M)      trigonometric function             2      1
  111.      sinf        sin(3M)      trigonometric function             1
  112.      sinh        sinh(3M)     hyperbolic function                2      3
  113.      sinhf       sinh(3M)     hyperbolic function                1
  114.      sqrt        sqrt(3M)     square root                        1      1
  115.      sqrtf       sqrt(3M)     square root                        1
  116.      tan         sin(3M)      trigonometric function             2      3
  117.      tanf        sin(3M)      trigonometric function             1
  118.      tanh        sinh(3M)     hyperbolic function                2      3
  119.      tanhf       sinh(3M)     hyperbolic function                1
  120.      trunc       floor(3M)    truncate to whole number           0      0
  121.      truncf      floor(3M)    truncate to whole number           0      0
  122.      y0          j0(3M)       bessel function                    ?      ?
  123.      y1          j0(3M)       bessel function                    ?      ?
  124.      yn          j0(3M)       bessel function                    ?      ?
  125.  
  126.  
  127.  
  128.                                                                         PPPPaaaaggggeeee 2222
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. MMMMAAAATTTTHHHH((((3333MMMM))))                                                              MMMMAAAATTTTHHHH((((3333MMMM))))
  136.  
  137.  
  138.  
  139. VVVVEEEECCCCTTTTOOOORRRR IIIINNNNTTTTRRRRIIIINNNNSSSSIIIICCCCSSSS
  140.      Beginning with IRIX 6.2, libm now supports the following vector
  141.      intrinsics:
  142.  
  143.      /* single precision vector routines */
  144.  
  145.  
  146.      vvvvaaaaccccoooossssffff(((( ffffllllooooaaaatttt ****xxxx,,,, ffffllllooooaaaatttt ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  147.      vvvvaaaassssiiiinnnnffff(((( ffffllllooooaaaatttt ****xxxx,,,, ffffllllooooaaaatttt ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  148.      vvvvaaaattttaaaannnnffff(((( ffffllllooooaaaatttt ****xxxx,,,, ffffllllooooaaaatttt ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  149.      vvvvccccoooossssffff((((  ffffllllooooaaaatttt ****xxxx,,,, ffffllllooooaaaatttt ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  150.      vvvveeeexxxxppppffff((((  ffffllllooooaaaatttt ****xxxx,,,, ffffllllooooaaaatttt ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  151.      vvvvllllooooggggffff((((  ffffllllooooaaaatttt ****xxxx,,,, ffffllllooooaaaatttt ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  152.      vvvvlllloooogggg11110000ffff(((( ffffllllooooaaaatttt ****xxxx,,,, ffffllllooooaaaatttt ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  153.      vvvvssssiiiinnnnffff((((  ffffllllooooaaaatttt ****xxxx,,,, ffffllllooooaaaatttt ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  154.      vvvvssssqqqqrrrrttttffff(((( ffffllllooooaaaatttt ****xxxx,,,, ffffllllooooaaaatttt ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  155.      vvvvttttaaaannnnffff((((  ffffllllooooaaaatttt ****xxxx,,,, ffffllllooooaaaatttt ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  156.  
  157.      /* double precision vector routines */
  158.  
  159.  
  160.      vvvvaaaaccccoooossss(((( ddddoooouuuubbbblllleeee ****xxxx,,,, ddddoooouuuubbbblllleeee ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  161.      vvvvaaaassssiiiinnnn(((( ddddoooouuuubbbblllleeee ****xxxx,,,, ddddoooouuuubbbblllleeee ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  162.      vvvvaaaattttaaaannnn(((( ddddoooouuuubbbblllleeee ****xxxx,,,, ddddoooouuuubbbblllleeee ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  163.      vvvvccccoooossss((((  ddddoooouuuubbbblllleeee ****xxxx,,,, ddddoooouuuubbbblllleeee ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  164.      vvvveeeexxxxpppp((((  ddddoooouuuubbbblllleeee ****xxxx,,,, ddddoooouuuubbbblllleeee ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  165.      vvvvlllloooogggg((((  ddddoooouuuubbbblllleeee ****xxxx,,,, ddddoooouuuubbbblllleeee ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  166.      vvvvlllloooogggg11110000(((( ddddoooouuuubbbblllleeee ****xxxx,,,, ddddoooouuuubbbblllleeee ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  167.      vvvvssssiiiinnnn((((  ddddoooouuuubbbblllleeee ****xxxx,,,, ddddoooouuuubbbblllleeee ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  168.      vvvvssssqqqqrrrrtttt(((( ddddoooouuuubbbblllleeee ****xxxx,,,, ddddoooouuuubbbblllleeee ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  169.      vvvvttttaaaannnn((((  ddddoooouuuubbbblllleeee ****xxxx,,,, ddddoooouuuubbbblllleeee ****yyyy,,,, lllloooonnnngggg ccccoooouuuunnnntttt,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeexxxx,,,, lllloooonnnngggg ssssttttrrrriiiiddddeeeeyyyy ))))
  170.  
  171.      Input and output arrays for the above routines should either be identical
  172.      or non-overlapping.
  173.  
  174.      On Mips4 processors, these routines are software pipelined to take
  175.      advantage of the multiple execution units.  On that machine, throughput
  176.      is up to several times greater than one gets by calling the scalar
  177.      intrinsics repeatedly.  On processors other than the Mips4, these
  178.      routines are still available; although not software pipelined on those
  179.      processors, they still eliminate considerable call overhead when they can
  180.      be used.  Note that the vector routines do not support denormals on the
  181.      Mips4 processors.
  182.  
  183.      The single precision vector routines can also be called by the names
  184.      vfacos, vfasin, etc.
  185.  
  186.      Semantics of these routines:
  187.  
  188.      i=0, 1, ..., count-1:  y[i*stridey] = f(x[i*stridex])
  189.  
  190.      Example:
  191.  
  192.  
  193.  
  194.                                                                         PPPPaaaaggggeeee 3333
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201. MMMMAAAATTTTHHHH((((3333MMMM))))                                                              MMMMAAAATTTTHHHH((((3333MMMM))))
  202.  
  203.  
  204.  
  205.      double x[10000], y[10000];
  206.  
  207.  
  208.      for (i=0; i<1000; i++ ) y[2*i] = sin(x[3*i]);
  209.  
  210.      Transform (by hand) into
  211.  
  212.      vsin(x, y, 1000, 3, 2);
  213.  
  214.  
  215.      Vector and scalar routines may differ slightly, however none of the
  216.      results differ from the mathematically correct result by more than 2 ulps
  217.      (units in the last place).  Note that the vector square root routines are
  218.      less accurate than the hardware versions; vsqrt and vsqrtf use the
  219.      reciprocal square root instruction and lose up to about 2 bits of
  220.      accuracy.  vsqrt and vfsqrt give correct answers for zero and infinite
  221.      arguments.
  222.  
  223. LLLLOOOONNNNGGGG DDDDOOOOUUUUBBBBLLLLEEEE AAAARRRRIIIITTTTHHHHMMMMEEEETTTTIIIICCCC
  224.      Long double arithmetic is supported by the MIPSpro compiler.  The
  225.      representation used is not IEEE compliant; long doubles are represented
  226.      on this system as the sum or difference of two doubles, normalized so
  227.      that the smaller double is <= .5 ulp of the larger.  This is equivalent
  228.      to a 107 bit mantissa with an 11 bit biased exponent (bias = 1023), and 1
  229.      sign bit.  In terms of decimal precision, this is approximately 34
  230.      decimal digits.
  231.  
  232.      Long double constants are coded as double precision constants followed by
  233.      the letter 'l' (upper or lower case).  The largest (finite) long double
  234.      constant is 1.797693134862315807937289714053023e308L .
  235.      The smallest long double precision constant is
  236.      4.940656458412465441765687928682213e-324L .  Long doubles less than
  237.      1.805194375864829576069262081173746e-276L
  238.      may require a double denormal in their representation and therefore
  239.      contain less than 107 bits precision.
  240.  
  241.      Long double NaNs and (signed) infinities are supported by the MIPSpro
  242.      compiler.  Long double infinity is represented as the sum of a double
  243.      infinity and a double zero; similarly for NaNs.
  244.  
  245.      In Fortran, long doubles are denoted by the term REAL *16.
  246.  
  247.      In general, long double arithmetic operations (+, -, *, /) are not
  248.      precisely rounded, but are accurate to approximately 3 ulps.
  249.  
  250.      Note that long double arithmetic operations are done in software by
  251.      MIPSpro compilers; results of these operations may vary slightly from
  252.      release to release due to improvements in the algorithms which implement
  253.      them.
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.                                                                         PPPPaaaaggggeeee 4444
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267. MMMMAAAATTTTHHHH((((3333MMMM))))                                                              MMMMAAAATTTTHHHH((((3333MMMM))))
  268.  
  269.  
  270.  
  271.      Long double operations on this system are only supported in round to
  272.      nearest rounding mode (the default).  The system must be in round to
  273.      nearest rounding mode when issuing long double arithmetic operations or
  274.      calling any of the long double functions, or incorrect answers will
  275.      result.
  276.  
  277. DDDDIIIIFFFFFFFFEEEERRRREEEENNNNCCCCEEEESSSS BBBBEEEETTTTWWWWEEEEEEEENNNN ----oooo33332222,,,, ----nnnn33332222,,,, ----66664444
  278.      For the IRIX 6.2 release, faster and more accurate algorithms were
  279.      implemented, and vector functions were added to the math library. In
  280.      order to maintain numerical compatibility with older releases, these
  281.      changes were made only in the -n32 and -64 versions of the library and
  282.      not in the -o32 version.  ( Where there are differences in accuracy, this
  283.      document describes the behavior of the -n32 and -64 versions of the
  284.      library. )
  285.  
  286.      To take advantage of the new functions and algorithms, you need to
  287.      compile and link using either the -n32 or the -64 option.
  288.  
  289.      Note however, that the -o32 version of libmx contains all routines
  290.      present in the -n32 and -64 versions of libmx except the quad precision
  291.      and vector routines, and gives results identical to the -n32 and -64
  292.      versions.
  293.  
  294. NNNNOOOOTTTTEEEESSSS
  295.      Users concerned with portability to other computer systems should note
  296.      that the long double and float versions of these functions are optional
  297.      according to the ANSI C Programming Language Specification ISO/IEC 9899 :
  298.      1990 (E).
  299.  
  300.      Long double functions have been renamed to be compliant with the ANSI-C
  301.      standard, however to be backward compatible, they may still be called
  302.      with the double precision function name prefixed with a q.  (Exceptions:
  303.      functions _f_a_b_s_l and _f_m_o_d_l may be called with names _q_a_b_s and _q_m_o_d, resp.)
  304.  
  305.      In 4.3BSD, distributed from the University of California in late 1985,
  306.      most of the foregoing functions come in two versions, one for the
  307.      double-precision "D" format in the DEC VAX-11 family of computers,
  308.      another for double-precision arithmetic conforming to the IEEE Standard
  309.      754 for Binary Floating-point Arithmetic.  The two versions behave very
  310.      similarly, as should be expected from programs more accurate and robust
  311.      than was the norm when UNIX was born.  For instance, the programs are
  312.      accurate to within the numbers of _u_l_ps tabulated above; an _u_l_p is one
  313.      _Unit in the _Last _Place.  And the programs have been cured of anomalies
  314.      that afflicted the older math library _l_i_b_m in which incidents like the
  315.      following had been reported:
  316.           sqrt(-1.0) = 0.0 and log(-1.0) = -1.7e38.
  317.           cos(1.0e-11) > cos(0.0) > 1.0.
  318.           pow(x,1.0) != x when x = 2.0, 3.0, 4.0, ..., 9.0.
  319.           pow(-1.0,1.0e10) trapped on Integer Overflow.
  320.           sqrt(1.0e30) and sqrt(1.0e-30) were very slow.
  321.      This machine conforms to the IEEE Standard 754 for Binary Floating-point
  322.      Arithmetic, to which only the notes for IEEE floating-point apply and are
  323.  
  324.  
  325.  
  326.                                                                         PPPPaaaaggggeeee 5555
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333. MMMMAAAATTTTHHHH((((3333MMMM))))                                                              MMMMAAAATTTTHHHH((((3333MMMM))))
  334.  
  335.  
  336.  
  337.      included here.
  338.      (See however, the notes regarding long double precision below.)
  339.  
  340.      IIIIEEEEEEEEEEEE SSSSTTTTAAAANNNNDDDDAAAARRRRDDDD 777755554444 FFFFllllooooaaaattttiiiinnnngggg----ppppooooiiiinnnntttt AAAArrrriiiitttthhhhmmmmeeeettttiiiicccc::::
  341.  
  342.      This standard is on its way to becoming more widely adopted than any
  343.      other design for computer arithmetic.
  344.  
  345.      Properties of IEEE 754 Double-precision:
  346.           Wordsize: 64 bits, 8 bytes.  Radix: Binary.
  347.           Precision: 53 sig.  bits, roughly 16 sig.  decimals.
  348.                If x and x' are consecutive positive Double-precision numbers
  349.                (they differ by 1 _u_l_p), then
  350.                1.1e-16 < 0.5**53 < (x'-x)/x _< 0.5**52 < 2.3e-16.
  351.           Range: Overflow threshold  = 2.0**1024 = 1.8e308
  352.                  Underflow threshold = 0.5**1022 = 2.2e-308
  353.                Overflow goes by default to a signed Infinity.
  354.                Underflow is _G_r_a_d_u_a_l, rounding to the nearest integer multiple
  355.                of 0.5**1074 = 4.9e-324.
  356.           Zero is represented ambiguously as +0 or -0.
  357.                Its sign transforms correctly through multiplication or
  358.                division, and is preserved by addition of zeros with like
  359.                signs; but x-x yields +0 for every finite x.  The only
  360.                operations that reveal zero's sign are division by zero and
  361.                copysign(x,+_0).  In particular, comparison (x > y, x _> y, etc.)
  362.                cannot be affected by the sign of zero; but if finite x = y
  363.                then Infinity = 1/(x-y) != -1/(y-x) = -Infinity.
  364.           Infinity is signed.
  365.                it persists when added to itself or to any finite number.  Its
  366.                sign transforms correctly through multiplication and division,
  367.                and (finite)/+_Infinity = +_0 (nonzero)/0 = +_Infinity.  But
  368.                Infinity-Infinity, Infinity*0 and Infinity/Infinity are, like
  369.                0/0 and sqrt(-3), invalid operations that produce _N_a_N.
  370.           Reserved operands:
  371.                there are 2**53-2 of them, all called _N_a_N (_Not _a _Number).
  372.                Some, called Signaling _N_a_Ns, trap any floating-point operation
  373.                performed upon them; they could be used to mark missing or
  374.                uninitialized values, or nonexistent elements of arrays.  The
  375.                rest are Quiet _N_a_Ns; they are the default results of Invalid
  376.                Operations, and propagate through subsequent arithmetic
  377.                operations.  If x != x then x is _N_a_N; every other predicate (x
  378.                > y, x = y, x < y, ...) is FALSE if _N_a_N is involved.
  379.                NOTE: Trichotomy is violated by _N_a_N.
  380.                     Besides being FALSE, predicates that entail ordered
  381.                     comparison, rather than mere (in)equality, signal Invalid
  382.                     Operation when _N_a_N is involved.
  383.           Rounding:
  384.                Every algebraic operation (+, -, *, /, sqrt) is rounded by
  385.                default to within half an _u_l_p, and when the rounding error is
  386.                exactly half an _u_l_p then the rounded value's least significant
  387.                bit is zero.  This kind of rounding is usually the best kind,
  388.                sometimes provably so; for instance, for every x = 1.0, 2.0,
  389.  
  390.  
  391.  
  392.                                                                         PPPPaaaaggggeeee 6666
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399. MMMMAAAATTTTHHHH((((3333MMMM))))                                                              MMMMAAAATTTTHHHH((((3333MMMM))))
  400.  
  401.  
  402.  
  403.                3.0, 4.0, ..., 2.0**52, we find (x/3.0)*3.0 == x and
  404.                (x/10.0)*10.0 == x and ...  despite that both the quotients and
  405.                the products have been rounded.  Only rounding like IEEE 754
  406.                can do that.  But no single kind of rounding can be proved best
  407.                for every circumstance, so IEEE 754 provides rounding towards
  408.                zero or towards +Infinity or towards -Infinity at the
  409.                programmer's option.
  410.           Exceptions:
  411.                IEEE 754 recognizes five kinds of floating-point exceptions,
  412.                listed below in declining order of probable importance.
  413.                     Exception              Default Result
  414.                     -------                -------
  415.                     Invalid Operation      _N_a_N, or FALSE
  416.                     Overflow               +_Infinity
  417.                     Divide by Zero         +_Infinity
  418.                     Underflow              Gradual Underflow
  419.                     Inexact                Rounded value
  420.                NOTE:  An Exception is not an Error unless handled badly.  What
  421.                makes a class of exceptions exceptional is that no single
  422.                default response can be satisfactory in every instance.  On the
  423.                other hand, if a default response will serve most instances
  424.                satisfactorily, the unsatisfactory instances cannot justify
  425.                aborting computation every time the exception occurs.
  426.  
  427.           For each kind of floating-point exception, IEEE 754 provides a Flag
  428.           that is raised each time its exception is signaled, and stays raised
  429.           until the program resets it.  Programs may also test, save and
  430.           restore a flag.  Thus, IEEE 754 provides three ways by which
  431.           programs may cope with exceptions for which the default result might
  432.           be unsatisfactory:
  433.  
  434.           1)  Test for a condition that might cause an exception later, and
  435.               branch to avoid the exception.
  436.  
  437.           2)  Test a flag to see whether an exception has occurred since the
  438.               program last reset its flag.
  439.  
  440.           3)  Test a result to see whether it is a value that only an
  441.               exception could have produced.
  442.               CAUTION: The only reliable ways to discover whether Underflow
  443.               has occurred are to test whether products or quotients lie
  444.               closer to zero than the underflow threshold, or to test the
  445.               Underflow flag.  (Sums and differences cannot underflow in IEEE
  446.               754; if x != y then x-y is correct to full precision and
  447.               certainly nonzero regardless of how tiny it may be.)  Products
  448.               and quotients that underflow gradually can lose accuracy
  449.               gradually without vanishing, so comparing them with zero (as one
  450.               might on a VAX) will not reveal the loss.  Fortunately, if a
  451.               gradually underflowed value is destined to be added to something
  452.               bigger than the underflow threshold, as is almost always the
  453.               case, digits lost to gradual underflow will not be missed
  454.               because they would have been rounded off anyway.  So gradual
  455.  
  456.  
  457.  
  458.                                                                         PPPPaaaaggggeeee 7777
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465. MMMMAAAATTTTHHHH((((3333MMMM))))                                                              MMMMAAAATTTTHHHH((((3333MMMM))))
  466.  
  467.  
  468.  
  469.               underflows are usually _p_r_o_v_a_b_l_y ignorable.  The same cannot be
  470.               said of underflows flushed to 0.
  471.  
  472.           At the option of an implementor conforming to IEEE 754, other ways
  473.           to cope with exceptions may be provided:
  474.  
  475.           4)  ABORT.  This mechanism classifies an exception in advance as an
  476.               incident to be handled by means traditionally associated with
  477.               error-handling statements like "ON ERROR GO TO ...".  Different
  478.               languages offer different forms of this statement, but most
  479.               share the following characteristics:
  480.  
  481.           -   No means is provided to substitute a value for the offending
  482.               operation's result and resume computation from what may be the
  483.               middle of an expression.  An exceptional result is abandoned.
  484.  
  485.           -   In a subprogram that lacks an error-handling statement, an
  486.               exception causes the subprogram to abort within whatever program
  487.               called it, and so on back up the chain of calling subprograms
  488.               until an error-handling statement is encountered or the whole
  489.               task is aborted and memory is dumped.
  490.  
  491.           5)  STOP.  This mechanism, requiring an interactive debugging
  492.               environment, is more for the programmer than the program.  It
  493.               classifies an exception in advance as a symptom of a
  494.               programmer's error; the exception suspends execution as near as
  495.               it can to the offending operation so that the programmer can
  496.               look around to see how it happened.  Quite often the first
  497.               several exceptions turn out to be quite unexceptionable, so the
  498.               programmer ought ideally to be able to resume execution after
  499.               each one as if execution had not been stopped.
  500.  
  501.           6)  ... Other ways lie beyond the scope of this document.
  502.  
  503.      The crucial problem for exception handling is the problem of Scope, and
  504.      the problem's solution is understood, but not enough manpower was
  505.      available to implement it fully in time to be distributed in 4.3BSD's
  506.      _l_i_b_m.  Ideally, each elementary function should act as if it were
  507.      indivisible, or atomic, in the sense that ...
  508.  
  509.      i)    No exception should be signaled that is not deserved by the data
  510.            supplied to that function.
  511.  
  512.      ii)   Any exception signaled should be identified with that function
  513.            rather than with one of its subroutines.
  514.  
  515.      iii)  The internal behavior of an atomic function should not be disrupted
  516.            when a calling program changes from one to another of the five or
  517.            so ways of handling exceptions listed above, although the
  518.            definition of the function may be correlated intentionally with
  519.            exception handling.
  520.  
  521.  
  522.  
  523.  
  524.                                                                         PPPPaaaaggggeeee 8888
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531. MMMMAAAATTTTHHHH((((3333MMMM))))                                                              MMMMAAAATTTTHHHH((((3333MMMM))))
  532.  
  533.  
  534.  
  535.      Ideally, every programmer should be able _c_o_n_v_e_n_i_e_n_t_l_y to turn a debugged
  536.      subprogram into one that appears atomic to its users.  But simulating all
  537.      three characteristics of an atomic function is still a tedious affair,
  538.      entailing hosts of tests and saves/restores; work is under way to
  539.      ameliorate the inconvenience.
  540.  
  541.      Meanwhile, the functions in _l_i_b_m are only approximately atomic.  They
  542.      signal no inappropriate exception except possibly ...
  543.           Over/Underflow
  544.                when a result, if properly computed, might have lain barely
  545.                within range, and
  546.           Inexact in _c_a_b_s, _c_b_r_t, _h_y_p_o_t, _l_o_g_1_0 and _p_o_w
  547.                when it happens to be exact, thanks to fortuitous cancellation
  548.                of errors.
  549.      Otherwise, ...
  550.           Invalid Operation is signaled only when
  551.                any result but _N_a_N would probably be misleading.
  552.           Overflow is signaled only when
  553.                the exact result would be finite but beyond the overflow
  554.                threshold.
  555.           Divide-by-Zero is signaled only when
  556.                a function takes exactly infinite values at finite operands.
  557.           Underflow is signaled only when
  558.                the exact result would be nonzero but tinier than the underflow
  559.                threshold.
  560.           Inexact is signaled only when
  561.                greater range or precision would be needed to represent the
  562.                exact result.
  563.  
  564.      Exceptions on this machine:
  565.           The exception enables and the flags that are raised when an
  566.           exception occurs (as well as the rounding mode) are in the
  567.           floating-point control and status register.  This register can be
  568.           read or written by the routines described on the man page _f_p_c(3C).
  569.           This register's layout is described in the file <_s_y_s/_f_p_u._h>.
  570.  
  571.           A useful set of ``user trap handlers'' is available.  See the man
  572.           page _s_i_g_f_p_e(3C).
  573.  
  574.           The raw interface to the hardware registers is only intended to be
  575.           used by the code to implement IEEE user trap handlers.  IEEE
  576.           floating-point exceptions are enabled by setting the enable bit for
  577.           that exception in the floating-point control and status register.
  578.           If an exception then occurs the UNIX signal SIGFPE is sent to the
  579.           process.  It is up to the signal handler to determine the
  580.           instruction that caused the exception and to take the action
  581.           specified by the user.  The instruction that caused the exception is
  582.           in one of two places.  If the floating-point board is used (the
  583.           floating-point implementation revision register indicates this in
  584.           its implementation field) then the instruction that caused the
  585.           exception is in the floating-point exception instruction register.
  586.           In all other implementations the instruction that caused the
  587.  
  588.  
  589.  
  590.                                                                         PPPPaaaaggggeeee 9999
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597. MMMMAAAATTTTHHHH((((3333MMMM))))                                                              MMMMAAAATTTTHHHH((((3333MMMM))))
  598.  
  599.  
  600.  
  601.           exception is at the address of the program counter as modified by
  602.           the branch delay bit in the cause register.  Both the program
  603.           counter and cause register are in the sigcontext structure passed to
  604.           the signal handler (see _s_i_g_n_a_l(2)).  If the program is to be
  605.           continued past the instruction that caused the exception the program
  606.           counter in the signal context must be advanced.  If the instruction
  607.           is in a branch delay slot then the branch must be emulated to
  608.           determine if the branch is taken and then the resulting program
  609.           counter can be calculated (see _e_m_u_l_a_t_e__b_r_a_n_c_h(3X) and _s_i_g_n_a_l(2)).
  610.           Note however, that on systems using the R8000 processor, floating
  611.           point exceptions are generally fatal when trapped unless the process
  612.           is being run in precise exception mode.
  613.  
  614.  
  615. PPPPLLLLAAAATTTTFFFFOOOORRRRMMMM SSSSPPPPEEEECCCCIIIIFFFFIIIICCCC LLLLIIIIBBBBRRRRAAAARRRRIIIIEEEESSSS
  616.      When compiling -n32 or -64, each processor has specially tuned, hardware
  617.      specific, versions of _l_i_b_m and _l_i_b_f_a_s_t_m, that the run time linker will
  618.      use, by default, whenever available.
  619.  
  620.      The R10000 tuned libraries are found in the directories:
  621.           /usr/lib32/mips4/r10000/
  622.           /usr/lib64/mips4/r10000/
  623.  
  624.      The R8000 tuned libraries are found in the directories:
  625.           /usr/lib32/mips4/r8000/
  626.           /usr/lib64/mips4/r8000/
  627.  
  628.      The R5000 tuned libraries are found in the directories:
  629.           /usr/lib32/mips4/
  630.           /usr/lib64/mips4/
  631.  
  632.      And the R4000 tuned libraries are found in the directories:
  633.           /usr/lib32/mips3/
  634.           /usr/lib64/mips3/
  635.  
  636.      At runtime, each program automatically uses the "best" library for the
  637.      system on which it is executing. For example, if the executing program is
  638.      a mip3 program designed to run on an r4000 processor, it will still use
  639.      the mips4 R1000-tuned math library when running on an r10000 system.
  640.  
  641.  
  642. BBBBUUUUGGGGSSSS
  643.      When signals are appropriate, they are emitted by certain operations
  644.      within the codes, so a subroutine-trace may be needed to identify the
  645.      function with its signal in case method 5) above is in use.  And the
  646.      codes all take the IEEE 754 defaults for granted; this means that a
  647.      decision to trap all divisions by zero could disrupt a code that would
  648.      otherwise get correct results despite division by zero.
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.                                                                        PPPPaaaaggggeeee 11110000
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663. MMMMAAAATTTTHHHH((((3333MMMM))))                                                              MMMMAAAATTTTHHHH((((3333MMMM))))
  664.  
  665.  
  666.  
  667. SEE ALSO
  668.      signal(2), fpc(3C), emulate_branch(3X), sigfpe(3C), matherr(3M)
  669.      R2010 Floating Point Coprocessor Architecture
  670.      R2360 Floating Point Board Product Description
  671.      An explanation of IEEE 754 and its proposed extension p854 was published
  672.      in the IEEE magazine MICRO in August 1984 under the title "A Proposed
  673.      Radix- and Word-length-independent Standard for Floating-point
  674.      Arithmetic" by W. J. Cody et al.  Articles in the IEEE magazine COMPUTER
  675.      vol. 14 no. 3 (Mar.  1981), and in the ACM SIGNUM Newsletter Special
  676.      Issue of Oct. 1979, may be helpful although they pertain to superseded
  677.      drafts of the standard.
  678.  
  679. AAAAUUUUTTTTHHHHOOOORRRR
  680.      W. Kahan, with the help of Z-S. Alex Liu, Stuart I. McDonald, Dr.
  681.      Kwok-Choi Ng, Peter Tang.
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.                                                                        PPPPaaaaggggeeee 11111111
  723.  
  724.  
  725.  
  726.