Submitter:CFP
Submission Date: 2026-08-03
Document: WG14 N3947
Proposal category:Technical
Title: nexttoward and nextafter
Reference Documents:SC22WG14.36462, CFP issue #31

Summary

Herbert Tong raised a question about nexttoward and nextafter. nexttoward refers back to nextafter; however, nextafter does the wrong thing for nexttoward for the arguments.

The call:

nexttoward( 1.0, 1.L+DBL_EPSILON/4.L )

if done as per the existing words in nextafter [convert both arguments to return type] is
nexttoward( (double)1.0, (double)(1.L+DBL_EPSILON/4.L) )

is the same as
nextafter( 1.0, (double)(1.L+DBL_EPSILON/4.L) )

which is
nextafter( 1.0, 1.0 )

which is 1.0, instead of the correct 1.0+DBL_EPSILON.

Proposal

Change N3886 7.12.12.3 The nextafter functions; paragraph 2:

The nextafter functions determine the next representable value, in the return type of the function, after x in the direction of y, where x and y are first converted to the return type of the function.

Change N3886 7.12.12.3 The nextafter functions; paragraph 2 NOTE:

The argument values are converted to the return type of the function, even by a macro implementation of the function. For decimal floating types, Table 5.2 specifies the preferred quantum exponent of the result.