1 '\" te
   2 .\" Copyright (c) 2001, the Institute of Electrical and Electronics Engineers, Inc. and The Open Group. All Rights Reserved.
   3 .\" Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
   4 .\" Portions Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
   5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at 
   6 .\" http://www.opengroup.org/bookstore/.
   7 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
   8 .\"  This notice shall appear on any product containing this material.
   9 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
  10 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
  11 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
  12 .TH nextafter 3M "12 Jul 2006" "SunOS 5.11" "Mathematical Library Functions"
  13 .SH NAME
  14 nextafter, nextafterf, nextafterl, nexttoward, nexttowardf, nexttowardl \- next
  15 representable double-precision floating-point number
  16 .SH SYNOPSIS
  17 .LP
  18 .nf
  19 c99 [ \fIflag\fR... ] \fIfile\fR... \fB-lm\fR [ \fIlibrary\fR... ]
  20 #include <math.h>
  21 
  22 \fBdouble\fR \fBnextafter\fR(\fBdouble\fR \fIx\fR, \fBdouble\fR \fIy\fR);
  23 .fi
  24 
  25 .LP
  26 .nf
  27 \fBfloat\fR \fBnextafterf\fR(\fBfloat\fR \fIx\fR, \fBfloat\fR \fIy\fR);
  28 .fi
  29 
  30 .LP
  31 .nf
  32 \fBlong double\fR \fBnextafterl\fR(\fBlong double\fR \fIx\fR, \fBlong double\fR \fIy\fR);
  33 .fi
  34 
  35 .LP
  36 .nf
  37 \fBdouble\fR \fBnexttoward\fR(\fBdouble\fR \fIx\fR, \fBlong double\fR \fIy\fR);
  38 .fi
  39 
  40 .LP
  41 .nf
  42 \fBfloat\fR \fBnexttowardf\fR(\fBfloat\fR \fIx\fR, \fBlong double\fR \fIy\fR);
  43 .fi
  44 
  45 .LP
  46 .nf
  47 \fBlong double\fR \fBnexttowardl\fR(\fBlong double\fR \fIx\fR, \fBlong double\fR \fIy\fR);
  48 .fi
  49 
  50 .SH DESCRIPTION
  51 .sp
  52 .LP
  53 The \fBnextafter()\fR, \fBnextafterf()\fR, and \fBnextafterl()\fR functions
  54 compute the next representable floating-point value following \fIx\fR in the
  55 direction of \fIy\fR. Thus, if \fIy\fR is less than \fIx\fR, \fBnextafter()\fR
  56 returns the largest representable floating-point number less than \fIx\fR. The
  57 \fBnextafter()\fR, \fBnextafterf()\fR, and \fBnextafterl()\fR functions return
  58 \fIy\fR if \fIx\fR equals \fIy\fR.
  59 .sp
  60 .LP
  61 The \fBnexttoward()\fR, \fBnexttowardf()\fR, and \fBnexttowardl()\fR functions
  62 are equivalent to the corresponding \fBnextafter()\fR functions, except that
  63 the second parameter has type \fBlong double\fR and the functions return
  64 \fIy\fR converted to the type of the function if \fIx\fR equals \fIy\fR.
  65 .SH RETURN VALUES
  66 .sp
  67 .LP
  68 Upon successful completion, these functions return the next representable
  69 floating-point value following \fIx\fR in the direction of \fIy\fR.
  70 .sp
  71 .LP
  72 If \fIx\fR == \fIy\fR, \fIy\fR (of the type \fIx\fR) is returned.
  73 .sp
  74 .LP
  75 If \fIx\fR is finite and the correct function value would overflow, a range
  76 error occurs and \(+-\fBHUGE_VAL\fR, \(+-\fBHUGE_VALF\fR, and
  77 \(+-\fBHUGE_VALL\fR (with the same sign as \fIx\fR) is returned as appropriate
  78 for the return type of the function.
  79 .sp
  80 .LP
  81 If \fIx\fR or \fIy\fR is NaN, a NaN is returned.
  82 .sp
  83 .LP
  84 If \fIx\fR != \fIy\fR and the correct function value is subnormal, zero, or
  85 underflows, a range error occurs and either the correct function value (if
  86 representable) or 0.0 is returned.
  87 .SH ERRORS
  88 .sp
  89 .LP
  90 These functions will fail if:
  91 .sp
  92 .ne 2
  93 .mk
  94 .na
  95 \fBRange Error\fR
  96 .ad
  97 .RS 15n
  98 .rt  
  99 The correct value overflows.
 100 .sp
 101 If the integer expression (\fBmath_errhandling\fR & \fBMATH_ERREXCEPT\fR) is
 102 non-zero, the overflow floating-point exception is raised.
 103 .sp
 104 The \fBnextafter()\fR function sets \fBerrno\fR to \fBERANGE\fR if the correct
 105 value would overflow.
 106 .RE
 107 
 108 .sp
 109 .ne 2
 110 .mk
 111 .na
 112 \fBRange Error\fR
 113 .ad
 114 .RS 15n
 115 .rt  
 116 The correct value underflows.
 117 .sp
 118 If the integer expression (\fBmath_errhandling\fR & \fBMATH_ERREXCEPT\fR) is
 119 non-zero, the underflow floating-point exception is raised.
 120 .RE
 121 
 122 .SH USAGE
 123 .sp
 124 .LP
 125 An application wanting to check for exceptions should call
 126 \fBfeclearexcept\fR(\fBFE_ALL_EXCEPT\fR) before calling these functions. On
 127 return, if \fBfetestexcept\fR(\fBFE_INVALID\fR | \fBFE_DIVBYZERO\fR |
 128 \fBFE_OVERFLOW\fR | \fBFE_UNDERFLOW\fR) is non-zero, an exception has been
 129 raised. An application should either examine the return value or check the
 130 floating point exception flags to detect exceptions.
 131 .sp
 132 .LP
 133 An application can also set \fBerrno\fR to 0 before calling \fBnextafter()\fR.
 134 On return, if \fBerrno\fR is non-zero, an error has occurred. The
 135 \fBnextafterf()\fR, \fBnextafterl()\fR. \fBnexttoward()\fR,
 136 \fBnexttowardf()\fR, and \fBnexttowardl()\fR functions do not set \fBerrno\fR.
 137 .SH ATTRIBUTES
 138 .sp
 139 .LP
 140 See \fBattributes\fR(5) for descriptions of the following attributes:
 141 .sp
 142 
 143 .sp
 144 .TS
 145 tab() box;
 146 cw(2.75i) |cw(2.75i) 
 147 lw(2.75i) |lw(2.75i) 
 148 .
 149 ATTRIBUTE TYPEATTRIBUTE VALUE
 150 _
 151 Interface StabilityStandard
 152 _
 153 MT-LevelMT-Safe
 154 .TE
 155 
 156 .SH SEE ALSO
 157 .sp
 158 .LP
 159 \fBfeclearexcept\fR(3M), \fBfetestexcept\fR(3M), \fBmath.h\fR(3HEAD),
 160 \fBattributes\fR(5), \fBstandards\fR(5)