LoginSignup
0
0

7.12 Mathematics <math.h>, CN3054:2022 (20) p239.c

Last updated at Posted at 2022-11-21

はじめに(Introduction)

N3054 Working Draft, Standard for Programming Language C

C++ nは、ISO/IEC JTC1 SC22 WG14の作業原案(Working Draft)です。
公式のISO/IEC 9899原本ではありません。

ISO/IEC JTC1 SC22 のWG14を含むいくつかのWGでは、可能な限り作業文書を公開し、幅広い意見を求めています。

ISO/IEC JTC1 SC7からISO/IEC JTC1 SC22リエゾンとして、2000年頃、C/C++の品質向上に貢献しようとした活動をしていたことがあります。その頃は、まだISO/IEC TS 17961の原案が出る前です。Cの精神が優勢で、セキュリティ対策は補助的な位置付けでした。ISO/IEC TS 17961の制定と、C/C++のライブラリ類の見直しと、C++の進化はどんどん進んでいきます。 

進化の具合が、どちらに行こうとしているかは、コンパイルて実行させてみないとわかりません。C/C++の規格案の電子ファイルは、そのままコンパイルできる形式であるとよいと主張してきました。MISRA-C/C++, CERTC/C++でも同様です。MISRA-C/C++は、Example Suiteという形で、コード断片をコンパイルできる形で提供するようになりました。

一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(gcc, clang)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C/C++, MISRA C/C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, 箱庭プロジェクト、g++(GCC), clang++(LLVM)との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。

最新規格はCN3096

<この項は書きかけです。順次追記します。>

背景(back ground)

C/C++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに1回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。

過去に何度か、自分のネットでの記録に助けられたことがあります。

また
https://researchmap.jp/joub9b3my-1797580/#_1797580
に記載したサイトのお世話になっています。

作業方針(sequence)

clangでは--std=c11, -std=C17 -std=c2xの3種類
gccでは-std=c11, -std=C17 -std=c2xの3種類
でコンパイルし、

1)コンパイルエラーを収集する。
2)コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
3)リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
4)意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。

1)だけのものから4)まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。

bash
$ docker run -v /Users/ogawakiyoshi/n4910/n3540:/Users/ogawakiyoshi/n4910/n3540 -it kaizenjapan/n3540 /bin/bash

読書感想文

CコンパイラによるC言語規格の読書感想文として掲載しています。

コンパイル実験が、CN3242に対する、gccとclangによる感想文だということご理解いただけると幸いです。

読書感想文は人間かAIだけが作るものとは限りません。
本(電子書籍を含む)を入力として、その内容に対する文字列を読書感想文として受け止めましょう。
元の文章をあり方、コンパイルできるように電子化しておくこと、コンパイラが解釈可能な断片の作り方など。

個人開発

Cコンパイラの試験を一人でもくもくとやっているのは個人開発の一つの姿です。

<この項は書きかけです。順次追記します。>

編纂器(Compiler)

clang --version

Debian clang version 14.0.6-++20220622053050+f28c006a5895-1~exp1~20220622173135.152
Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin

gcc --version

gcc (GCC) 12.1.0 Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

7.12 Mathematics , CN3054:2022 (20) p239.c

算譜(source code)

p239.c
// CN3054 Committee Draft, Standard for Programming Language C
// http://www.open-std.org/jtc1/sc22/wg14/docs/papers/2022/n3054.pdf
const char * n3054 = "7.12 Mathematics <math.h>, CN3054:2022 (20) p239.c";
// Debian clang version 14.0.5-++20220610033153+c12386ae247c-
// g++ (GCC) 12.1.0 Copyright (C) 2022 Free Software Foundation, Inc.
// Edited by Dr. OGAWA Kiyoshi. Compile procedure and results record.
// C++N3054:2022 Standard Working Draft on ISO/IEC 14882(0) sample code compile list

#include "N3054.h"

// 7.12.2 The FP_CONTRACT pragma Synopsis
//  The FP_CONTRACT pragma can be used to allow (if the state is "on") or disallow (if the state is "off") the implementation to contract expressions (6.5). Each pragma can occur either outside external declarations or preceding all explicit declarations and statements inside a compound statement. When outside external declarations, the pragma takes effect from its occurrence until another FP_CONTRACT pragma is encountered, or until the end of the translation unit. When inside a compound statement, the pragma takes effect from its occurrence until another FP_CONTRACT pragma is encountered (including within a nested compound statement), or until the end of the compound statement; at the end of a compound statement the state for the pragma is restored to its condition just before the compound statement. If this pragma is used in any other context, the behavior is undefined. The default state ("on" or "off") for the pragma is implementation-defined.
// 7.12.3 Classification macros
//  Floating-point values can be classified as NaN, infinite, normal, subnormal, or zero, or into other implementation-defined categories. Numbers whose magnitude is at least bemin−1 (the minimum magnitude of normalized floating-point numbers in the type) and at most (1 − b−p)bemax (the maximum magnitude of normalized floating-point numbers in the type), where b, p, emin, and emax are as in 5.2.4.2.2, are classified as normal. Larger magnitude finite numbers represented with full precision in the type may also be classified as normal. Nonzero numbers whose magnitude is less than bemin−1 are classified as subnormal.
// 283)Ordinary accuracy is determined by the implementation. It refers to the accuracy of the function where results are not compromised by extreme magnitude.
// 284)The term underflow here is intended to encompass both "gradual underflow" as in IEC 60559 and also "flush-to-zero" underflow. IEC 60559 underflow can occur in cases where the magnitude of the rounded result (accurate to the full precision of the type) equals the minimum normalized number in the format.
// 285)Math errors are being indicated by the floating-point exception flags rather than by errno.
//         Description
#include <math.h>
#pragma STDC FP_CONTRACT on-off-switch
//  In the synopses in this subclause, real-floating indicates that the argument shall be an expression of real floating type.
// 7.12.3.1 The fpclassify macro Synopsis
//  The fpclassify macro classifies its argument value as NaN, infinite, normal, subnormal, zero, or into another implementation-defined category. First, an argument represented in a format wider than its semantic type is converted to its semantic type. Then classification is based on the type of the argument.286)
// Returns
//  The fpclassify macro returns the value of the number classification macro appropriate to the value of its argument.
// 7.12.3.2 The iscanonical macro Synopsis
//  The iscanonical macro determines whether its argument value is canonical (5.2.4.2.2). First, an argument represented in a format wider than its semantic type is converted to its semantic type. Then, determination is based on the type of the argument.
// Returns
//  The iscanonical macro returns a nonzero value if and only if its argument is canonical. 
// 7.12.3.3 The isfinite macro
// Synopsis
//  The isfinite macro determines whether its argument has a finite value (zero, subnormal, or normal, and not infinite or NaN). First, an argument represented in a format wider than its semantic type is converted to its semantic type. Then determination is based on the type of the argument.
// Returns
//  The isfinite macro returns a nonzero value if and only if its argument has a finite value. 
// 7.12.3.4 The isinf macro
// Synopsis
//   Description
// Description
// Description
#include <math.h>
int fpclassify(real-floating x);
 #include <math.h>
int iscanonical(real-floating x);
#include <math.h>
int isfinite(real-floating x);
#include <math.h>
int isinf(real-floating x);
// 286)Since an expression can be evaluated with more range and precision than its type has, it is important to know the type that classification is based on. For example, a normal long double value might become subnormal when converted to double, and zero when converted to float.
// Description
//  The isinf macro determines whether its argument value is (positive or negative) infinity. First, an argument represented in a format wider than its semantic type is converted to its semantic type. Then determination is based on the type of the argument.
// Returns
//  The isinf macro returns a nonzero value if and only if its argument has an infinite value. 
// 7.12.3.5 The isnan macro
// Synopsis
//  The isnan macro determines whether its argument value is a NaN. First, an argument represented in a format wider than its semantic type is converted to its semantic type. Then determination is based on the type of the argument.287)
// Returns
//  The isnan macro returns a nonzero value if and only if its argument has a NaN value. 
// 7.12.3.6 The isnormal macro
// Synopsis
//  The isnormal macro determines whether its argument value is normal (neither zero, subnormal, infinite, nor NaN). First, an argument represented in a format wider than its semantic type is converted to its semantic type. Then determination is based on the type of the argument.
// Returns
// The isnormal macro returns a nonzero value if and only if its argument has a normal value. 7.12.3.7 The signbit macro
// Synopsis
//  The signbit macro determines whether the sign of its argument value is negative288). If the argument value is an unsigned zero, its sign is regarded as positive. Otherwise, if the argument value is unsigned, the result value (zero or nonzero) is implementation-defined.
// Returns
//  The signbit macro returns a nonzero value if and only if the sign of its argument value is determined to be negative.
// 7.12.3.8 The issignaling macro
// 287)For the isnan macro, the type for determination does not matter unless the implementation supports NaNs in the evaluation type but not in the semantic type.
// 88)The signbit macro determines the sign of all values, including infinities, zeros, and NaNs.
//  Description
//  Description
// Description
#include <math.h>
int isnan(real-floating x);
              #include <math.h>
int isnormal(real-floating x);
                 #include <math.h>
int signbit(real-floating x);
//  The issignaling macro determines whether its argument value is a signaling NaN. Returns
//  The issignaling macro returns a nonzero value if and only if its argument is a signaling NaN.289) 
// 7.12.3.9 The issubnormal macro
// Synopsis
//  The issubnormal macro determines whether its argument value is subnormal. First, an argument represented in a format wider than its semantic type is converted to its semantic type. Then determination is based on the type of the argument.
// Returns
//  The issubnormal macro returns a nonzero value if and only if its argument is subnormal. 
// 7.12.3.10 The iszero macro
// Synopsis
//  The iszero macro determines whether its argument value is (positive, negative, or unsigned) zero. First, an argument represented in a format wider than its semantic type is converted to its semantic type. Then, determination is based on the type of the argument.
// Returns
//  The iszero macro returns a nonzero value if and only if its argument is zero.
// 7.12.4 Trigonometric functions 
// 7.12.4.1 The acos functions Synopsis
// Description
//  Description
// Description
#include <math.h>
int issignaling(real-floating x);
#include <math.h>
int issubnormal(real-floating x);
#include <math.h>
int iszero(real-floating x);
#include <math.h>
double acos(double x);
float acosf(float x);
long double acosl(long double x); 
#ifdef __STDC_IEC_60559_DFP__ _Decimal32 
acosd32(_Decimal32 x); _
Decimal64 acosd64(_Decimal64 x);
 _Decimal128 acosd128(_Decimal128 x); 
#endif
// 289)F.3 specifies that issignaling (and all the other classification macros), raise no floating-point exception if the argument is a variable, or any other expression whose value is represented in the format of its semantic type, even if the value is a signaling NaN.
// Description
//  The acos functions compute the principal value of the arc cosine of x. A domain error occurs for arguments not in the interval [−1, +1].
Returns
//  The acos functions return arccos x in the interval [0, π] radians.
// 7.12.4.2 The asin functions
// Synopsis
#include <math.h>
double asin(double x);
float asinf(float x);
long double asinl(long double x); 
#ifdef __STDC_IEC_60559_DFP__ _Decimal32 
asind32(_Decimal32 x); 
_Decimal64 asind64(_Decimal64 x); 
_Decimal128 asind128(_Decimal128 x); 
#endif
//  Description
//  The asin functions compute the principal value of the arc sine of x. A domain error occurs for arguments not in the interval [−1, +1]. A range error occurs if nonzero x is too close to zero.
// Returns
//  The asin functions return arcsin x in the interval [− π , + π ] radians. 22
// 7.12.4.3 The atan functions Synopsis
#include <math.h>
double atan(double x);
float atanf(float x);
long double atanl(long double x);
#ifdef __STDC_IEC_60559_DFP__ 
_Decimal32 atand32(_Decimal32 x); 
_Decimal64 atand64(_Decimal64 x); 
_Decimal128 atand128(_Decimal128 x); 
#endif
//  Description
//  The atan functions compute the principal value of the arc tangent of x. A range error occurs if nonzero x is too close to zero.
// Returns
//  The atan functions return arctan x in the interval [− π , + π ] radians. 22
// 7.12.4.4 The atan2 functions Synopsis
#include <math.h>
double atan2(double y, double x);
float atan2f(float y, float x);
long double atan2l(long double y, long double x); 
#ifdef __STDC_IEC_60559_DFP__
_Decimal32 atan2d32(_Decimal32 y, _Decimal32 x); 
_Decimal64 atan2d64(_Decimal64 y, _Decimal64 x);
 _Decimal128 atan2d128(_Decimal128 y, _Decimal128 x); 
#endif
// Description
//  The atan2 functions compute the value of the arc tangent of y/x, using the signs of both arguments to determine the quadrant of the return value. A domain error may occur if both arguments are zero.
A range error occurs if x is positive and nonzero y is too close to zero. x
// Returns
//  The atan2 functions return arctan(y/x) in the interval [−π, +π] radians. 7.12.4.5 The cos functions
// Synopsis
//  The cos functions compute the cosine of x (measured in radians). Returns
3 The cos functions return cos x. 7.12.4.6 The sin functions
// Synopsis
//  The sin functions compute the sine of x (measured in radians). A range error occurs if nonzero x is too close to zero.
// Returns
//  The sin functions return sin x. 7.12.4.7 The tan functions
// Synopsis
//  The tan functions return the tangent of x (measured in radians). A range error occurs if nonzero x is too close to zero.
#include <math.h>
double cos(double x);
float cosf(float x);
long double cosl(long double x); 
#ifdef __STDC_IEC_60559_DFP__ 
_Decimal32 cosd32(_Decimal32 x); 
_Decimal64 cosd64(_Decimal64 x); 
_Decimal128 cosd128(_Decimal128 x); 
#endif
//  Description
#include <math.h>
double sin(double x);
float sinf(float x);
long double sinl(long double x); 
#ifdef __STDC_IEC_60559_DFP__ 
_Decimal32 sind32(_Decimal32 x); 
_Decimal64 sind64(_Decimal64 x); 
_Decimal128 sind128(_Decimal128 x); 
#endif
//  Description
#include <math.h>
double tan(double x);
float tanf(float x);
long double tanl(long double x); 
#ifdef __STDC_IEC_60559_DFP__ 
_Decimal32 tand32(_Decimal32 x); 
_Decimal64 tand64(_Decimal64 x); 
_Decimal128 tand128(_Decimal128 x); 
#endif
// Description
//  Returns
//  The tan functions return tan x. 7.12.4.8 The acospi functions
Synopsis
#include <math.h>
double acospi(double x);
float acospif(float x);
long double acospil(long double x); 
#ifdef __STDC_IEC_60559_DFP__ 
_Decimal32 acospid32(_Decimal32 x); 
_Decimal64 acospid64(_Decimal64 x); 
_Decimal128 acospid128(_Decimal128 x); 
#endif
//  Description
//  The acospi functions compute the principal value of the arc cosine of x, divided by π, thus measur- ing the angle in half-revolutions. A domain error occurs for arguments not in the interval [−1, +1].
// Returns
//  The acospi functions return arccos(x)/π in the interval [0, 1]. // // 7.12.4.9 The asinpi functions
// Synopsis
#include <math.h>
double asinpi(double x);
float asinpif(float x);
long double asinpil(long double x); 
#ifdef __STDC_IEC_60559_DFP__ 
_Decimal32 asinpid32(_Decimal32 x); _Decimal64 asinpid64(_Decimal64 x); 
_Decimal128 asinpid128(_Decimal128 x); 
#endif
//  Description
//  The asinpi functions compute the principal value of the arc sine of x, divided by π, thus measuring the angle in half-revolutions. A domain error occurs for arguments not in the interval [−1, +1]. A range error occurs if nonzero x is too close to zero.
Returns
//  The asinpi functions return arcsin(x)/π in the interval [− 1 , + 1 ]. 22
// 7.12.4.10 The atanpi functions Synopsis
#include <math.h>
double atanpi(double x);
float atanpif(float x);
long double atanpil(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 atanpid32(_Decimal32 x); _Decimal64 atanpid64(_Decimal64 x); _Decimal128 atanpid128(_Decimal128 x); #endif
// Description
//  The atanpi functions compute the principal value of the arc tangent of x, divided by π, thus measuring the angle in half-revolutions. A range error occurs if nonzero x is too close to zero.
// Returns
//  The atanpi functions return arctan(x)/π. in the interval [− 1 , + 1 ]. 22
// 7.12.4.11 The atan2pi functions Synopsis
//  The atan2pi functions compute the angle, measured in half-revolutions, subtended at the origin by the point (x, y) and the positive x-axis. Thus, the atan2pi functions compute arctan( y )/π, in the x range [−1, +1]. A domain error may occur if both arguments are zero. A range error occurs if x is positive and nonzero y is too close to zero. x
// Returns
//  The atan2pi functions return the computed angle, in the interval [−1, +1]. 7.12.4.12 The cospi functions
// Synopsis
//  The cospi functions compute the cosine of π × x, thus regarding x as a measurement in half- revolutions.
// Returns
// The cospi functions return cos(π × x). 7.12.4.13 The sinpi functions
// Synopsis
#include <math.h>
double atan2pi(double y, double x);
float atan2pif(float y, float x);
long double atan2pil(long double y, long double x); 
#ifdef __STDC_IEC_60559_DFP__
_Decimal32 atan2pid32(_Decimal32 y, _Decimal32 x); 
_Decimal64 atan2pid64(_Decimal64 y, _Decimal64 x); 
_Decimal128 atan2pid128(_Decimal128 y, _Decimal128 x);
#endif
// Description
#include <math.h>
double cospi(double x);
float cospif(float x);
long double cospil(long double x); 
#ifdef __STDC_IEC_60559_DFP__ 
_Decimal32 cospid32(_Decimal32 x); 
_Decimal64 cospid64(_Decimal64 x); 
_Decimal128 cospid128(_Decimal128 x); 
#endif
//  Description
#include <math.h>
double sinpi(double x);
float sinpif(float x);
long double sinpil(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 sinpid32(_Decimal32 x); _Decimal64 sinpid64(_Decimal64 x);
                        § 7.12.4.13
Library 247

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054
          Description
2 The sinpi functions compute the sine of π×x, thus regarding x as a measurement in half-revolutions. A range error occurs if nonzero x is too close to zero.
Returns
3 The sinpi functions return sin(π × x). 7.12.4.14 The tanpi functions
Synopsis
1
2 The tanpi functions compute the tagent of π × x, thus regarding x as a measurement in half- revolutions. A range error occurs if nonzero x is too close to zero.
Returns
3 The tanpi functions return tan(π × x).
7.12.5 Hyperbolic functions 7.12.5.1 The acosh functions Synopsis
1
2 The acosh functions compute the (nonnegative) arc hyperbolic cosine of x. A domain error occurs for arguments less than 1.
Returns
3 The acosh functions return arcosh x in the interval [0, +]. 7.12.5.2 The asinh functions
Synopsis
1
        #include <math.h>
double tanpi(double x);
float tanpif(float x);
long double tanpil(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 tanpid32(_Decimal32 x); _Decimal64 tanpid64(_Decimal64 x); _Decimal128 tanpid128(_Decimal128 x); #endif
                            Description
        #include <math.h>
double acosh(double x);
float acoshf(float x);
long double acoshl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 acoshd32(_Decimal32 x); _Decimal64 acoshd64(_Decimal64 x); _Decimal128 acoshd128(_Decimal128 x); #endif
                            Description
        #include <math.h>
double asinh(double x);
float asinhf(float x);
long double asinhl(long double x);
         248
Library
§ 7.12.5.2
_Decimal128 sinpid128(_Decimal128 x); #endif
 
N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E)
#ifdef __STDC_IEC_60559_DFP__ _Decimal32 asinhd32(_Decimal32 x); _Decimal64 asinhd64(_Decimal64 x); _Decimal128 asinhd128(_Decimal128 x); #endif
                         Description
2 The asinh functions compute the arc hyperbolic sine of x. A range error occurs if nonzero x is too close to zero.
Returns
3 The asinh functions return arsinh x. 7.12.5.3 The atanh functions
Synopsis
1
2 The atanh functions compute the arc hyperbolic tangent of x. A domain error occurs for arguments not in the interval [1, +1]. A pole error may occur if the argument equals -1 or +1. A range error occurs if nonzero x is too close to zero.
Returns
3 The atanh functions return artanh x. 7.12.5.4 The cosh functions
Synopsis
1
2 The cosh functions compute the hyperbolic cosine of x. A range error occurs if the magnitude of finite x is too large.
         #include <math.h>
double atanh(double x);
float atanhf(float x);
long double atanhl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 atanhd32(_Decimal32 x); _Decimal64 atanhd64(_Decimal64 x); _Decimal128 atanhd128(_Decimal128 x); #endif
                                    Description
         #include <math.h>
double cosh(double x);
float coshf(float x);
long double coshl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 coshd32(_Decimal32 x); _Decimal64 coshd64(_Decimal64 x); _Decimal128 coshd128(_Decimal128 x); #endif
                                    Description
Returns
3 The cosh functions return cosh x. 7.12.5.5 The sinh functions
Synopsis
1 #include <math.h> § 7.12.5.5
Library 249
         
ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054
    double sinh(double x);
float sinhf(float x);
long double sinhl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 sinhd32(_Decimal32 x); _Decimal64 sinhd64(_Decimal64 x); _Decimal128 sinhd128(_Decimal128 x); #endif
                         Description
2 The sinh functions compute the hyperbolic sine of x. A range error occurs if the magnitude of finite x is too large or if nonzero x is too close to zero.
Returns
3 The sinh functions return sinh x. 7.12.5.6 The tanh functions
Synopsis
1
2 The tanh functions compute the hyperbolic tangent of x. A range error occurs if nonzero x is too close to zero.
Returns
3 The tanh functions return tanh x.
7.12.6 Exponential and logarithmic functions 7.12.6.1 The exp functions
Synopsis
1
2 The exp functions compute the base-e exponential of x. A range error occurs if the magnitude of finite x is too large.
Returns
3 The exp functions return ex . 7.12.6.2 The exp10 functions
        #include <math.h>
double tanh(double x);
float tanhf(float x);
long double tanhl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 tanhd32(_Decimal32 x); _Decimal64 tanhd64(_Decimal64 x); _Decimal128 tanhd128(_Decimal128 x); #endif
                            Description
        #include <math.h>
double exp(double x);
float expf(float x);
long double expl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 expd32(_Decimal32 x); _Decimal64 expd64(_Decimal64 x); _Decimal128 expd128(_Decimal128 x); #endif
                            Description
250
Library § 7.12.6.2

N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E) Synopsis
1
         #include <math.h>
double exp10(double x);
float exp10f(float x);
long double exp10l(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 exp10d32(_Decimal32 x); _Decimal64 exp10d64(_Decimal64 x); _Decimal128 exp10d128(_Decimal128 x); #endif
                                    Description
2 The exp10 functions compute the base-10 exponential of x. A range error occurs if the magnitude of finite x is too large.
Returns
3 The exp10 functions return 10x . 7.12.6.3 The exp10m1 functions
Synopsis
1
         #include <math.h>
double exp10m1(double x);
float exp10m1f(float x);
long double exp10m1l(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 exp10m1d32(_Decimal32 x); _Decimal64 exp10m1d64(_Decimal64 x); _Decimal128 exp10m1d128(_Decimal128 x); #endif
                                    Description
2 The exp10m1 functions compute the base-10 exponential of the argument, minus 1. A range error occurs if positive finite x is too large or if nonzero x is too close to zero.
Returns
3 The exp10m1 functions return 10x  1. 7.12.6.4 The exp2 functions
Synopsis
1
         #include <math.h>
double exp2(double x);
float exp2f(float x);
long double exp2l(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 exp2d32(_Decimal32 x); _Decimal64 exp2d64(_Decimal64 x); _Decimal128 exp2d128(_Decimal128 x); #endif
                                    Description
2 The exp2 functions compute the base-2 exponential of x. A range error occurs if the magnitude of finite x is too large.
Returns
3 The exp2 functions return 2x . § 7.12.6.4
Library 251

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054 7.12.6.5 The exp2m1 functions
Synopsis
1
        #include <math.h>
double exp2m1(double x);
float exp2m1f(float x);
long double exp2m1l(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 exp2m1d32(_Decimal32 x); _Decimal64 exp2m1d64(_Decimal64 x); _Decimal128 exp2m1d128(_Decimal128 x); #endif
                            Description
2 The exp2m1 functions compute the base-2 exponential of the argument, minus 1. A range error occurs if positive finite x is too large or if nonzero x is too close to zero.
Returns
3 The exp2m1 functions return 2x  1. 7.12.6.6 The expm1 functions
Synopsis
1
        #include <math.h>
double expm1(double x);
float expm1f(float x);
long double expm1l(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 expm1d32(_Decimal32 x); _Decimal64 expm1d64(_Decimal64 x); _Decimal128 expm1d128(_Decimal128 x); #endif
                            Description
2 The expm1 functions compute the base-e exponential of the argument, minus 1. A range error occurs if positive finite x is too large or if nonzero x is too close to zero. 290)
Returns
3 The expm1 functions return ex  1. 7.12.6.7 The frexp functions
Synopsis
1
        #include <math.h>
double frexp(double value, int *p);
float frexpf(float value, int *p);
long double frexpl(long double value, int *p); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 frexpd32(_Decimal32 value, int *p); _Decimal64 frexpd64(_Decimal64 value, int *p); _Decimal128 frexpd128(_Decimal128 value, int *p); #endif
                            Description
2 The frexp functions break a floating-point number into a normalized fraction and an integer exponent. They store the integer in the int object pointed to by p. If the type of the function is a
290)For small magnitude x, expm1(x) is expected to be more accurate than exp(x)-1.
252 Library § 7.12.6.7
 
N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E) standard floating type, the exponent is an integral power of 2. If the type of the function is a decimal
floating type, the exponent is an integral power of 10. Returns
3 If value is not a floating-point number or if the integral power is outside the range of int, the results
are unspecified. Otherwise, the frexp functions return the value x, such that x has a magnitude
in the interval [ 1 , 1) or zero, and value equals x × 2*p , when the type of the function is a standard 2
floating type; or x has a magnitude in the interval [1/10, 1) or zero, and value equals x × 10*p , when the type of the function is a decimal floating type. If value is zero, both parts of the result are zero.
7.12.6.8 The ilogb functions Synopsis
1
2 The ilogb functions extract the exponent of x as a signed int value. If x is zero they compute the value FP_ILOGB0; if x is infinite they compute the value INT_MAX; if x is a NaN they compute the value FP_ILOGBNAN; otherwise, they are equivalent to calling the corresponding logb function and converting the returned value to type int. A domain error or range error may occur if x is zero, infinite, or NaN. If the correct value is outside the range of the return type, the numeric result is unspecified and a domain error or range error may occur.
Returns
3 The ilogb functions return the exponent of x as a signed int value. Forward references: the logb functions (7.12.6.17).
7.12.6.9 The ldexp functions Synopsis
1
2 The ldexp functions multiply a floating-point number by an integral power of 2 when the type of the function is a standard floating type, or by an integral power of 10 when the type of the function is a decimal floating type. A range error occurs for some finite x, depending on p.
Returns
3 The ldexp functions return x × 2p when the type of the function is a standard floating type, or return x × 10p when the type of the function is a decimal floating type.
          #include <math.h>
int ilogb(double x);
int ilogbf(float x);
int ilogbl(long double x); #ifdef __STDC_IEC_60559_DFP__ int ilogbd32(_Decimal32 x); int ilogbd64(_Decimal64 x); int ilogbd128(_Decimal128 x); #endif
                                    Description
         #include <math.h>
double ldexp(double x, int p);
float ldexpf(float x, int p);
long double ldexpl(long double x, int p); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 ldexpd32(_Decimal32 x, int p); _Decimal64 ldexpd64(_Decimal64 x, int p); _Decimal128 ldexpd128(_Decimal128 x, int p); #endif
                                    Description
7.12.6.10 The llogb functions § 7.12.6.10
Library 253

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054 Synopsis
1
        #include <math.h>
long int llogb(double x);
long int llogbf(float x);
long int llogbl(long double x); #ifdef __STDC_IEC_60559_DFP__
long int llogbd32(_Decimal32 x); long int llogbd64(_Decimal64 x); long int llogbd128(_Decimal128 x); #endif
                            Description
2 The llogb functions extract the exponent of x as a signed long int value. If x is zero they compute the value FP_LLOGB0; if x is infinite they compute the value LONG_MAX; if x is a NaN they compute the value FP_LLOGBNAN; otherwise, they are equivalent to calling the corresponding logb function and converting the returned value to type long int. A domain error or range error may occur if x is zero, infinite, or NaN. If the correct value is outside the range of the return type, the numeric result is unspecified.
Returns
3 The llogb functions return the exponent of x as a signed long int value. Forward references: the logb functions (7.12.6.17).
7.12.6.11 The log functions Synopsis
1
        #include <math.h>
double log(double x);
float logf(float x);
long double logl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 logd32(_Decimal32 x); _Decimal64 logd64(_Decimal64 x); _Decimal128 logd128(_Decimal128 x); #endif
                            Description
2 The log functions compute the base-e (natural) logarithm of x. A domain error occurs if the argument is less than zero. A pole error may occur if the argument is zero.
Returns
3 The log functions return loge x. 7.12.6.12 The log10 functions
Synopsis
1
        #include <math.h>
double log10(double x);
float log10f(float x);
long double log10l(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 log10d32(_Decimal32 x); _Decimal64 log10d64(_Decimal64 x); _Decimal128 log10d128(_Decimal128 x); #endif
                            254
Library
§ 7.12.6.12

N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E) Description
2 The log10 functions compute the base-10 (common) logarithm of x. A domain error occurs if the argument is less than zero. A pole error may occur if the argument is zero.
Returns
3 The log10 functions return log10 x. 7.12.6.13 The log10p1 functions
Synopsis
1
         #include <math.h>
double log10p1(double x);
float log10p1f(float x);
long double log10p1l(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 log10p1d32(_Decimal32 x); _Decimal64 log10p1d64(_Decimal64 x); _Decimal128 log10p1d128(_Decimal128 x); #endif
                                    Description
2 The log10p1 functions compute the base-10 logarithm of 1 plus the argument. A domain error occurs if the argument is less than 1. A pole error may occur if the argument equals 1. A range error occurs if nonzero x is too close to zero.
Returns
3 The log10p1 functions return log10(1 + x). 7.12.6.14 The log1p and logp1 functions
Synopsis
1
         #include <math.h>
double log1p(double x);
float log1pf(float x);
long double log1pl(long double x); double logp1(double x);
float logp1f(float x);
long double logp1l(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 log1pd32(_Decimal32 x); _Decimal64 log1pd64(_Decimal64 x); _Decimal128 log1pd128(_Decimal128 x); _Decimal32 logp1d32(_Decimal32 x); _Decimal64 logp1d64(_Decimal64 x); _Decimal128 logp1d128(_Decimal128 x); #endif
                                                            Description
2 The log1p functions are equivalent to the logp1 functions.291) These functions compute the base-e (natural) logarithm of 1 plus the argument.292) A domain error occurs if the argument is less than 1. A pole error may occur if the argument equals 1. A range error occurs if nonzero x is too close to zero.
Returns
3 The log1p and logp1 functions return loge(1 + x).
291)The logp1 functions are preferred for name consistency with the log10p1 and log2p1 functions.
292)Forsmallmagnitudex,logp1(x)isexpectedtobemoreaccuratethanlog(1 + x).
§ 7.12.6.14 Library 255
 
ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054 7.12.6.15 The log2 functions
Synopsis
1
2 The log2 functions compute the base-2 logarithm of x. A domain error occurs if the argument is less than zero. A pole error may occur if the argument is zero.
Returns
3 The log2 functions return log2 x. 7.12.6.16 The log2p1 functions
Synopsis
1
2 The log2p1 functions compute the base-2 logarithm of 1 plus the argument. A domain error occurs if the argument is less than 1. A pole error may occur if the argument equals 1. A range error occurs if nonzero x is too close to zero.
Returns
3 The log2p1 functions return log2(1+x). 7.12.6.17 The logb functions
Synopsis
1
2 The logb functions extract the exponent of x, as a signed integer value in floating-point format. If x is subnormal it is treated as though it were normalized; thus, for positive finite x,
1x×blogb(x) <b
        #include <math.h>
double log2(double x);
float log2f(float x);
long double log2l(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 log2d32(_Decimal32 x); _Decimal64 log2d64(_Decimal64 x); _Decimal128 log2d128(_Decimal128 x); #endif
                            Description
        #include <math.h>
double log2p1(double x);
float log2p1f(float x);
long double log2p1l(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 log2p1d32(_Decimal32 x); _Decimal64 log2p1d64(_Decimal64 x); _Decimal128 log2p1d128(_Decimal128 x); #endif
                            Description
        #include <math.h>
double logb(double x);
float logbf(float x);
long double logbl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 logbd32(_Decimal32 x); _Decimal64 logbd64(_Decimal64 x); _Decimal128 logbd128(_Decimal128 x); #endif
                            Description
256
Library § 7.12.6.17

N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E)
where b = FLT_RADIX if the type of the function is a standard floating type, or b = 10 if the type of the function is a decimal floating type. A domain error or pole error may occur if the argument is zero.
Returns
3 The logb functions return the signed exponent of x. 7.12.6.18 The modf functions
Synopsis
1
         #include <math.h>
double modf(double value, double *iptr);
float modff(float value, float *iptr);
long double modfl(long double value, long double *iptr); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 modfd32(_Decimal32 x, _Decimal32 *iptr); _Decimal64 modfd64(_Decimal64 x, _Decimal64 *iptr); _Decimal128 modfd128(_Decimal128 x, _Decimal128 *iptr); #endif
                                    Description
2 The modf functions break the argument value into integral and fractional parts, each of which has the same type and sign as the argument. They store the integral part (in floating-point format) in the object pointed to by iptr.
Returns
3 The modf functions return the signed fractional part of value. 7.12.6.19 The scalbn and scalbln functions
Synopsis
1
         #include <math.h>
double scalbn(double x, int n);
float scalbnf(float x, int n);
long double scalbnl(long double x, int n);
double scalbln(double x, long int n);
float scalblnf(float x, long int n);
long double scalblnl(long double x, long int n); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 scalbnd32(_Decimal32 x, int n); _Decimal64 scalbnd64(_Decimal64 x, int n); _Decimal128 scalbnd128(_Decimal128 x, int n); _Decimal32 scalblnd32(_Decimal32 x, long int n); _Decimal64 scalblnd64(_Decimal64 x, long int n); _Decimal128 scalblnd128(_Decimal128 x, long int n); #endif
                                                            Description
2 The scalbn and scalbln functions compute x × bn , where b = FLT_RADIX if the type of the function is a standard floating type, or b = 10 if the type of the function is a decimal floating type. A range error occurs for some finite x, depending on n.
Returns
3 The scalbn and scalbln functions return x × bn.
1
§ 7.12.7.1
Library 257
7.12.7 7.12.7.1 Synopsis
Power and absolute-value functions The cbrt functions

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054
        #include <math.h>
double cbrt(double x);
float cbrtf(float x);
long double cbrtl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 cbrtd32(_Decimal32 x); _Decimal64 cbrtd64(_Decimal64 x); _Decimal128 cbrtd128(_Decimal128 x); #endif
                            Description
2 The cbrt functions compute the real cube root of x. Returns
1
3 The cbrt functions return x 3 .
7.12.7.2 The compoundn functions Synopsis
1
         #include <stdint.h>
#include <math.h>
double compoundn(double x, long long int n);
float compoundnf(float x, long long int n);
long double compoundnl(long double x, long long int n); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 compoundnd32(_Decimal32 x, long long int n); _Decimal64 compoundnd64(_Decimal64 x, long long int n); _Decimal128 compoundnd128(_Decimal128 x, long long int n); #endif
                               Description
2 The compoundn functions compute 1 plus x, raised to the power n. A domain error occurs if x < 1. Depending on n, a range error occurs if either positive finite x is too large or if x is too near but not equal to -1. A pole error may occur if x equals 1 and n < 0.
Returns
3 The compoundn functions return (1 + x)n. 7.12.7.3 The fabs functions
Synopsis
1
2 The fabs functions compute the absolute value of x. Returns
3 The fabs functions return |x|. 7.12.7.4 The hypot functions
        #include <math.h>
double fabs(double x);
float fabsf(float x);
long double fabsl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 fabsd32(_Decimal32 x); _Decimal64 fabsd64(_Decimal64 x); _Decimal128 fabsd128(_Decimal128 x); #endif
                            Description
258
Library
§ 7.12.7.4

N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E) Synopsis
1
         #include <math.h>
double hypot(double x, double y);
float hypotf(float x, float y);
long double hypotl(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 hypotd32(_Decimal32 x, _Decimal32 y); _Decimal64 hypotd64(_Decimal64 x, _Decimal64 y); _Decimal128 hypotd128(_Decimal128 x, _Decimal128 y); #endif
                                    Description
2 The hypot functions compute the square root of the sum of the squares of x and y, without undue overflow or underflow. A range error occurs for some finite arguments.
3
4 The hypot functions return 􏰀x2 + y2. 7.12.7.5 The pow functions
Synopsis
1
Returns
          #include <math.h>
double pow(double x, double y);
float powf(float x, float y);
long double powl(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 powd32(_Decimal32 x, _Decimal32 y); _Decimal64 powd64(_Decimal64 x, _Decimal64 y); _Decimal128 powd128(_Decimal128 x, _Decimal128 y); #endif
                                    Description
2 The pow functions compute x raised to the power y. A domain error occurs if x is finite and less than zero and y is finite and not an integer value. A domain error may occur if x is zero and y is zero. Depending on y, a range error occurs if either the magnitude of nonzero finite x is too large or too near zero. A domain error or pole error may occur if x is zero and y is less than zero.
Returns
3 The pow functions return xy. 7.12.7.6 The pown functions
Synopsis
1
         #include <stdint.h>
#include <math.h>
double pown(double x, long long int n);
float pownf(float x, long long int n);
long double pownl(long double x, long long int n); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 pownd32(_Decimal32 x, long long int n); _Decimal64 pownd64(_Decimal64 x, long long int n); _Decimal128 pownd128(_Decimal128 x, long long int n); #endif
                                        § 7.12.7.6
Library 259

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054 Description
2 The pown functions compute x raised to the nth power. A pole error may occur if x equals 0 and n < 0. Depending on n, a range error occurs if either the magnitude of nonzero finite x is too large or too near zero.
Returns
3 The pown functions return xn. 7.12.7.7 The powr functions
Synopsis
1
        #include <math.h>
double powr(double y, double x);
float powrf(float y, float x);
long double powrl(long double y, long double x); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 powrd32(_Decimal32 y, _Decimal32 x); _Decimal64 powrd64(_Decimal64 y, _Decimal64 x); _Decimal128 powrd128(_Decimal128 y, _Decimal128 x); #endif
                            Description
2 The powr functions compute x raised to the power y as ey loge x .293)
or if x and y are both zero. Depending on y, a range error occurs if either positive nonzero finite x is too large or too near zero. A pole error may occur if x equals zero and finite y < 0.
Returns
3 The powr functions return ey loge x . 7.12.7.8 The rootn functions
Synopsis
1
Description
2 The rootn functions compute the principal nth root of x. A domain error occurs if n is 0 or if x < 0 and n is even. If n is 1, a range error occurs if either the magnitude of nonzero finite x is too large or too near zero. A pole error may occur if x equals zero and n < 0.
Returns
1
3 The rootn functions return x n . 7.12.7.9 The rsqrt functions
Synopsis
1
A domain error occurs if x < 0
        #include <stdint.h>
#include <math.h>
double rootn(double x, long long int n);
float rootnf(float x, long long int n);
long double rootnl(long double x, long long int n); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 rootnd32(_Decimal32 x, long long int n); _Decimal64 rootnd64(_Decimal64 x, long long int n); _Decimal128 rootnd128(_Decimal128 x, long long int n); #endif
                                        #include <math.h> double rsqrt(double x);
    293)Restricting the domain to that of the formula ey loge x is intended to better meet expectations for a continuous power function and to allow implementations with fewer tests for special cases.
260 Library § 7.12.7.9

N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E)
     float rsqrtf(float x);
long double rsqrtl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 rsqrtd32(_Decimal32 x); _Decimal64 rsqrtd64(_Decimal64 x); _Decimal128 rsqrtd128(_Decimal128 x); #endif
                            Description
2 The rsqrt functions compute the reciprocal of the nonnegative square root of the argument. A domain error occurs if the argument is less than zero. A pole error may occur if the argument equals zero.
Returns
3 The rsqrt functions return 1 . x
7.12.7.10 The sqrt functions Synopsis
1
2 The sqrt functions compute the nonnegative square root of x. A domain error occurs if the argument is less than zero.

           #include <math.h>
double sqrt(double x);
float sqrtf(float x);
long double sqrtl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 sqrtd32(_Decimal32 x); _Decimal64 sqrtd64(_Decimal64 x); _Decimal128 sqrtd128(_Decimal128 x); #endif
                                    Description
Returns

 3 The sqrt functions return x.
7.12.8 Error and gamma functions 7.12.8.1 The erf functions
Synopsis
1
2 The erf functions compute the error function of x. A range error occurs if nonzero x is too close to zero.
         #include <math.h>
double erf(double x);
float erff(float x);
long double erfl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 erfd32(_Decimal32 x); _Decimal64 erfd64(_Decimal64 x); _Decimal128 erfd128(_Decimal128 x); #endif
                                    Description
Returns
3 The erf functions return erf x = § 7.12.8.1
x
2 􏰅 et2 dt.

π
0
  Library 261

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054 7.12.8.2 The erfc functions
Synopsis
1
2 The erfc functions compute the complementary error function of x. A range error occurs if positive finite x is too large.
        #include <math.h>
double erfc(double x);
float erfcf(float x);
long double erfcl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 erfcd32(_Decimal32 x); _Decimal64 erfcd64(_Decimal64 x); _Decimal128 erfcd128(_Decimal128 x); #endif
                            Description
Returns
3 The erfc functions return erfcx = 1  erf x = 7.12.8.3 The lgamma functions
Synopsis
1

2 􏰅 et2 dt.

π
x
          #include <math.h>
double lgamma(double x);
float lgammaf(float x);
long double lgammal(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 lgammad32(_Decimal32 x); _Decimal64 lgammad64(_Decimal64 x); _Decimal128 lgammad128(_Decimal128 x); #endif
                            Description
2 The lgamma functions compute the natural logarithm of the absolute value of gamma of x. A range error occurs if positive finite x is too large. A pole error may occur if x is a negative integer or zero.
Returns
3 The lgamma functions return loge |Γ(x)|. 7.12.8.4 The tgamma functions
Synopsis
1
2 The tgamma functions compute the gamma function of x. A domain error or pole error may occur if x is a negative integer or zero. A range error occurs for some finite x less than zero, if positive finite x is too large, or nonzero x is too close to zero.
        #include <math.h>
double tgamma(double x);
float tgammaf(float x);
long double tgammal(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 tgammad32(_Decimal32 x); _Decimal64 tgammad64(_Decimal64 x); _Decimal128 tgammad128(_Decimal128 x); #endif
                            Description
262 Library § 7.12.8.4

N3054 working draft  September 3, 2022
ISO/IEC 9899:2023 (E)
Returns
3 The tgamma functions return Γ(x).
7.12.9 Nearest integer functions 7.12.9.1 The ceil functions
Synopsis
1
2 The ceil functions compute the smallest integer value not less than x. Returns
3 The ceil functions return x, expressed as a floating-point number. 7.12.9.2 The floor functions
Synopsis
1
2 The floor functions compute the largest integer value not greater than x. Returns
3 The floor functions return x, expressed as a floating-point number. 7.12.9.3 The nearbyint functions
Synopsis
1
2 The nearbyint functions round their argument to an integer value in floating-point format, using the current rounding direction and without raising the "inexact" floating-point exception.
         #include <math.h>
double ceil(double x);
float ceilf(float x);
long double ceill(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 ceild32(_Decimal32 x); _Decimal64 ceild64(_Decimal64 x); _Decimal128 ceild128(_Decimal128 x); #endif
                                    Description
         #include <math.h>
double floor(double x);
float floorf(float x);
long double floorl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 floord32(_Decimal32 x); _Decimal64 floord64(_Decimal64 x); _Decimal128 floord128(_Decimal128 x); #endif
                                    Description
         #include <math.h>
double nearbyint(double x);
float nearbyintf(float x);
long double nearbyintl(long double x); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 nearbyintd32(_Decimal32 x); _Decimal64 nearbyintd64(_Decimal64 x); _Decimal128 nearbyintd128(_Decimal128 x); #endif
                                    Description
§ 7.12.9.3 Library 263

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054 Returns
3 The nearbyint functions return the rounded integer value. 7.12.9.4 The rint functions
Synopsis
1
        #include <math.h>
double rint(double x);
float rintf(float x);
long double rintl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 rintd32(_Decimal32 x); _Decimal64 rintd64(_Decimal64 x); _Decimal128 rintd128(_Decimal128 x); #endif
                            Description
2 The rint functions differ from the nearbyint functions (7.12.9.3) only in that the rint functions may raise the "inexact" floating-point exception if the result differs in value from the argument.
Returns
3 The rint functions return the rounded integer value. 7.12.9.5 The lrint and llrint functions
Synopsis
1
        #include <math.h>
long int lrint(double x);
long int lrintf(float x);
long int lrintl(long double x);
long long int llrint(double x);
long long int llrintf(float x);
long long int llrintl(long double x); #ifdef __STDC_IEC_60559_DFP__
long int lrintd32(_Decimal32 x);
long int lrintd64(_Decimal64 x);
long int lrintd128(_Decimal128 x);
long long int llrintd32(_Decimal32 x); long long int llrintd64(_Decimal64 x); long long int llrintd128(_Decimal128 x); #endif
                                              Description
2 The lrint and llrint functions round their argument to the nearest integer value, rounding according to the current rounding direction. If the rounded value is outside the range of the return type, the numeric result is unspecified and a domain error or range error may occur.
Returns
3 The lrint and llrint functions return the rounded integer value. 7.12.9.6 The round functions
Synopsis
1
        #include <math.h>
double round(double x);
float roundf(float x);
long double roundl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 roundd32(_Decimal32 x);
               264
Library
§ 7.12.9.6

N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E)
              Description
2 The round functions round their argument to the nearest integer value in floating-point format, rounding halfway cases away from zero, regardless of the current rounding direction.
Returns
3 The round functions return the rounded integer value. 7.12.9.7 The lround and llround functions
Synopsis
1
         #include <math.h>
long int lround(double x);
long int lroundf(float x);
long int lroundl(long double x);
long long int llround(double x);
long long int llroundf(float x);
long long int llroundl(long double x); #ifdef __STDC_IEC_60559_DFP__
long int lroundd32(_Decimal32 x);
long int lroundd64(_Decimal64 x);
long int lroundd128(_Decimal128 x);
long long int llroundd32(_Decimal32 x); long long int llroundd64(_Decimal64 x); long long int llroundd128(_Decimal128 x); #endif
                                                            Description
2 The lround and llround functions round their argument to the nearest integer value, rounding halfway cases away from zero, regardless of the current rounding direction. If the rounded value is outside the range of the return type, the numeric result is unspecified and a domain error or range error may occur.
Returns
3 The lround and llround functions return the rounded integer value. 7.12.9.8 The roundeven functions
Synopsis
1
         #include <math.h>
double roundeven(double x);
float roundevenf(float x);
long double roundevenl(long double x); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 roundevend32(_Decimal32 x); _Decimal64 roundevend64(_Decimal64 x); _Decimal128 roundevend128(_Decimal128 x); #endif
                                    Description
_Decimal64 roundd64(_Decimal64 x); _Decimal128 roundd128(_Decimal128 x); #endif
   2 The roundeven functions round their argument to the nearest integer value in floating-point format, rounding halfway cases to even (that is, to the nearest value that is an even integer), regardless of the current rounding direction.
§ 7.12.9.8 Library 265

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054 Returns
3 The roundeven functions return the rounded integer value. 7.12.9.9 The trunc functions
Synopsis
1
2 The trunc functions round their argument to the integer value, in floating format, nearest to but no larger in magnitude than the argument.
Returns
3 The trunc functions return the truncated integer value. 7.12.9.10 The fromfp and ufromfp functions
Synopsis
1 #include <stdint.h> #include <math.h>
double fromfp(double x, int rnd, unsigned int width);
float fromfpf(float x, int rnd, unsigned int width);
long double fromfpl(long double x, int rnd, unsigned int width); double ufromfp(double x, int rnd, unsigned int width);
float ufromfpf(float x, int rnd, unsigned int width);
long double ufromfpl(long double x, int rnd, unsigned int width); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 fromfpd32(_Decimal32 x, int rnd, unsigned int width); _Decimal64 fromfpd64(_Decimal64 x, int rnd, unsigned int width); _Decimal128 fromfpd128(_Decimal128 x, int rnd, unsigned int width); _Decimal32 ufromfpd32(_Decimal32 x, int rnd, unsigned int width); _Decimal64 ufromfpd64(_Decimal64 x, int rnd, unsigned int width); _Decimal128 ufromfpd128(_Decimal128 x, int rnd, unsigned int width); #endif
Description
2 The fromfp and ufromfp functions round x, using the math rounding direction indicated by rnd, to a signed or unsigned integer, respectively. If width is nonzero and the resulting integer is within the range
 [2(width1), 2(width1)  1], for signed  [0, 2width  1], for unsigned
then the functions return the integer value (represented in floating type). Otherwise, if width is zero or x does not round to an integer within the range, the functions return a NaN (of the type of the x argument, if available), else the value of x, and a domain error occurs. If the value of the rnd argument is not equal to the value of a math rounding direction macro (7.12), the direction of rounding is unspecified. The fromfp and ufromfp functions do not raise the "inexact" floating-point exception.
        #include <math.h>
double trunc(double x);
float truncf(float x);
long double truncl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 truncd32(_Decimal32 x); _Decimal64 truncd64(_Decimal64 x); _Decimal128 truncd128(_Decimal128 x); #endif
                            Description
         266 Library § 7.12.9.10

N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E) Returns
3 The fromfp and ufromfp functions return the rounded integer value.
4 EXAMPLE Upward rounding of double x to type int, without raising the "inexact" floating-point
exception, is achieved by
(int)fromfp(x, FP_INT_UPWARD, INT_WIDTH)
5 EXAMPLE Unsigned integer wrapping is not performed in ufromfp(-3.0, FP_INT_UPWARD, UINT_WIDTH) /* domain error */
7.12.9.11 The fromfpx and ufromfpx functions Synopsis
1 #include <stdint.h> #include <math.h>
double fromfpx(double x, int rnd, unsigned int width);
float fromfpxf(float x, int rnd, unsigned int width);
long double fromfpxl(long double x, int rnd, unsigned int width); double ufromfpx(double x, int rnd, unsigned int width);
float ufromfpxf(float x, int rnd, unsigned int width);
long double ufromfpxl(long double x, int rnd, unsigned int width); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 fromfpxd32(_Decimal32 x, int rnd, unsigned int width); _Decimal64 fromfpxd64(_Decimal64 x, int rnd, unsigned int width); _Decimal128 fromfpxd128(_Decimal128 x, int rnd, unsigned int width); _Decimal32 ufromfpxd32(_Decimal32 x, int rnd, unsigned int width); _Decimal64 ufromfpxd64(_Decimal64 x, int rnd, unsigned int width); _Decimal128 ufromfpxd128(_Decimal128 x, int rnd, unsigned int width); #endif
Description
2 The fromfpx and ufromfpx functions differ from the fromfp and ufromfp functions, respectively, only in that the fromfpx and ufromfpx functions raise the "inexact" floating-point exception if a rounded result not exceeding the specified width differs in value from the argument x.
Returns
3 The fromfpx and ufromfpx functions return the rounded integer value.
4 NOTE 1 Conversions to integer types that are not required to raise the inexact exception can be done simply by rounding to integral value in floating type and then converting to the target integer type. For example, the conversion of long double x to uint64_t, using upward rounding, is done by
(uint64_t)ceill(x)
                                                7.12.10 7.12.10.1 Synopsis
1
Remainder functions The fmod functions
         #include <math.h>
double fmod(double x, double y);
float fmodf(float x, float y);
long double fmodl(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 fmodd32(_Decimal32 x, _Decimal32 y); _Decimal64 fmodd64(_Decimal64 x, _Decimal64 y); _Decimal128 fmodd128(_Decimal128 x, _Decimal128 y); #endif
                                    § 7.12.10.1
Library 267

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054 Description
2 The fmod functions compute the floating-point remainder of x/y. Returns
3 The fmod functions return the value x  ny, for some integer n such that, if y is nonzero, the result has the same sign as x and magnitude less than the magnitude of y. If y is zero, whether a domain error occurs or the fmod functions return zero is implementation-defined.
7.12.10.2 The remainder functions Synopsis
1
2 The remainder functions compute the remainder x REM y required by IEC 60559. 294) Returns
3 The remainder functions return x REM y. If y is zero, whether a domain error occurs or the functions return zero is implementation-defined.
7.12.10.3 The remquo functions Synopsis
1
2 The remquo functions compute the same remainder as the remainder functions. In the object pointed to by quo they store a value whose sign is the sign of x/y and whose magnitude is congruent modulo 2n to the magnitude of the integral quotient of x/y, where n is an implementation-defined integer greater than or equal to 3.
Returns
3 The remquo functions return x REM y. If y is zero, the value stored in the object pointed to by quo is unspecified and whether a domain error occurs or the functions return zero is implementation- defined.
4 NOTE 1 There are no decimal floating-point versions of the remquo functions.
7.12.11 Manipulation functions 7.12.11.1 The copysign functions Synopsis
1
        #include <math.h>
double remainder(double x, double y);
float remainderf(float x, float y);
long double remainderl(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 remainderd32(_Decimal32 x, _Decimal32 y); _Decimal64 remainderd64(_Decimal64 x, _Decimal64 y); _Decimal128 remainderd128(_Decimal128 x, _Decimal128 y); #endif
                            Description
        #include <math.h>
double remquo(double x, double y, int *quo);
float remquof(float x, float y, int *quo);
long double remquol(long double x, long double y, int *quo);
             Description
        #include <math.h>
double copysign(double x, double y);
    294)"When y ̸= 0, the remainder r = x REM y is defined regardless of the rounding mode by the mathematical relation r = x − ny, where n is the integer nearest the exact value of x ; whenever |n − x | = 1 , then n is even. If r = 0, its sign shall
   yy2 be that of x." This definition is applicable for all implementations.
268 Library § 7.12.11.1

N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E)
     float copysignf(float x, float y);
long double copysignl(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 copysignd32(_Decimal32 x, _Decimal32 y); _Decimal64 copysignd64(_Decimal64 x, _Decimal64 y); _Decimal128 copysignd128(_Decimal128 x, _Decimal128 y); #endif
                            Description
2 The copysign functions produce a value with the magnitude of x and the sign of y. If x or y is an unsigned value, the sign (if any) of the result is implementation-defined. On implementations that represent a signed zero but do not treat negative zero consistently in arithmetic operations, the copysign functions should regard the sign of zero as positive.
Returns
3 The copysign functions return a value with the magnitude of x and the sign of y. 7.12.11.2 The nan functions
Synopsis
1
         #include <math.h>
double nan(const char *tagp);
float nanf(const char *tagp);
long double nanl(const char *tagp); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 nand32(const char *tagp); _Decimal64 nand64(const char *tagp); _Decimal128 nand128(const char *tagp); #endif
                                    Description
2 The nan, nanf, and nanl functions convert the string pointed to by tagp according to the following rules.Thecallnan("n-char-sequence")isequivalenttostrtod("NAN(n-char-sequence)", nullptr); thecallnan("")isequivalenttostrtod("NAN()", nullptr).Iftagpdoesnotpointtoanempty stringorann-charsequence,thecallisequivalenttostrtod("NAN", nullptr).Callstonanfand nanl are equivalent to the corresponding calls to strtof and strtold.
Returns
3 The nan functions return a quiet NaN, if available, with content indicated through tagp. If the implementation does not support quiet NaNs, the functions return zero.
Forward references: the strtod, strtof, and strtold functions (7.24.1.5). 7.12.11.3 The nextafter functions
Synopsis
1
         #include <math.h>
double nextafter(double x, double y);
float nextafterf(float x, float y);
long double nextafterl(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 nextafterd32(_Decimal32 x, _Decimal32 y); _Decimal64 nextafterd64(_Decimal64 x, _Decimal64 y); _Decimal128 nextafterd128(_Decimal128 x, _Decimal128 y); #endif
                                    § 7.12.11.3
Library 269

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054 Description
2 The nextafter functions determine the next representable value, in the type of the function, after x in the direction of y, where x and y are first converted to the type of the function.295) The nextafter functions return y if x equals y.
A range error occurs if the magnitude of x is the largest finite value representable in the type and the resultisinfiniteornotrepresentableinthetype.Ifx != y,arangeerroroccursforeithersubnormal or zero results.
Returns
3 The nextafter functions return the next representable value in the specified format after x in the direction of y.
7.12.11.4 The nexttoward functions Synopsis
1
        #include <math.h>
double nexttoward(double x, long double y);
float nexttowardf(float x, long double y);
long double nexttowardl(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 nexttowardd32(_Decimal32 x, _Decimal128 y); _Decimal64 nexttowardd64(_Decimal64 x, _Decimal128 y); _Decimal128 nexttowardd128(_Decimal128 x, _Decimal128 y); #endif
                            Description
2 The nexttoward functions are equivalent to the nextafter functions except that the second param- eterhastypelong doubleor_Decimal128andthefunctionsreturnyconvertedtothetypeofthe function if x equals y.296)
7.12.11.5 The nextup functions Synopsis
1
        #include <math.h>
double nextup(double x);
float nextupf(float x);
long double nextupl(long double x); #ifdef __STDC_IEC_60559_DFP__ _Decimal32 nextupd32(_Decimal32 x); _Decimal64 nextupd64(_Decimal64 x); _Decimal128 nextupd128(_Decimal128 x); #endif
                            Description
2 The nextup functions determine the next representable value, in the type of the function, greater than x. If x is the negative number of least magnitude in the type of x, nextup(x) is 0 if the type has signed zeros and is 0 otherwise. If x is zero, nextup(x) is the positive number of least magnitude in the type of x. If x is the positive number (finite or infinite) of maximum magnitude in the type, nextup(x) is x.
Returns
3 The nextup functions return the next representable value in the specified type greater than x. 7.12.11.6 The nextdown functions
295)The argument values are converted to the type of the function, even by a macro implementation of the function.
296)The result of the nexttoward functions is determined in the type of the function, without loss of range or precision in a floating second argument.
 270 Library § 7.12.11.6

N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E) Synopsis
1
2 The nextdown functions determine the next representable value, in the type of the function, less than x. If x is the positive number of least magnitude in the type of x, nextdown(x) is +0 if the type has signed zeros and is 0 otherwise. If x is zero, nextdown(x) is the negative number of least magnitude in the type of x. If x is the negative number (finite or infinite) of maximum magnitude in the type, nextdown(x) is x.
Returns
3 The nextdown functions return the next representable value in the specified type less than x. 7.12.11.7 The canonicalize functions
Synopsis
1
2 The canonicalize functions attempt to produce a canonical version of the floating-point repre- sentation in the object pointed to by the argument x, as if to a temporary object of the specified type, and store the canonical result in the object pointed to by the argument cx.297) If the input *x is a signaling NaN, the canonicalize functions are intended to store a canonical quiet NaN. If a canonical result is not produced the object pointed to by cx is unchanged.
Returns
3 The canonicalize functions return zero if a canonical result is stored in the object pointed to by cx. Otherwise they return a nonzero value.
7.12.12 Maximum, minimum, and positive difference functions 7.12.12.1 The fdim functions
Synopsis
1
         #include <math.h>
double nextdown(double x);
float nextdownf(float x);
long double nextdownl(long double x); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 nextdownd32(_Decimal32 x); _Decimal64 nextdownd64(_Decimal64 x); _Decimal128 nextdownd128(_Decimal128 x); #endif
                                    Description
         #include <math.h>
int canonicalize(double * cx, const double * x);
int canonicalizef(float * cx, const float * x);
int canonicalizel(long double * cx, const long double * x); #ifdef __STDC_IEC_60559_DFP__
int canonicalized32(_Decimal32 * cx, const _Decimal32 * x); int canonicalized64(_Decimal64 * cx, const _Decimal64 * x); int canonicalized128(_Decimal128 * cx, const _Decimal128 * x); #endif
                                    Description
         #include <math.h>
double fdim(double x, double y);
float fdimf(float x, float y);
long double fdiml(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 fdimd32(_Decimal32 x, _Decimal32 y); _Decimal64 fdimd64(_Decimal64 x, _Decimal64 y);
                         297)Arguments x and cx may point to the same object.
§ 7.12.12.1 Library 271

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054
_Decimal128 fdimd128(_Decimal128 x, _Decimal128 y); #endif
           Description
2 The fdim functions determine the positive difference between their arguments: 􏰃xy ifx>y
+0 if x  y
A range error occurs for some finite arguments.
Returns
3 The fdim functions return the positive difference value. 7.12.12.2 The fmax functions
Synopsis
1
2 The fmax functions determine the maximum numeric value of their arguments.298) Returns
3 The fmax functions return the maximum numeric value of their arguments. 7.12.12.3 The fmin functions
Synopsis
1
2 The fmin functions determine the minimum numeric value of their arguments. 299)
Returns
3 The fmin functions return the minimum numeric value of their arguments.
4 NOTE 1 The fmax and fmin functions are similar to the fmaximum_num and fminimum_num functions, though may differ in which signed zero is returned when the arguments are differently signed zeros and in their treatment of signaling NaNs (see F.10.9.5).
298)Quiet NaN arguments are treated as missing data: if one argument is a quiet NaN and the other numeric, then the fmax functions choose the numeric value. See F.10.9.2.
299)The fmin functions are analogous to the fmax functions in their treatment of quiet NaNs.
272 Library § 7.12.12.3
        #include <math.h>
double fmax(double x, double y);
float fmaxf(float x, float y);
long double fmaxl(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 fmaxd32(_Decimal32 x, _Decimal32 y); _Decimal64 fmaxd64(_Decimal64 x, _Decimal64 y); _Decimal128 fmaxd128(_Decimal128 x, _Decimal128 y); #endif
                            Description
        #include <math.h>
double fmin(double x, double y);
float fminf(float x, float y);
long double fminl(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 fmind32(_Decimal32 x, _Decimal32 y); _Decimal64 fmind64(_Decimal64 x, _Decimal64 y); _Decimal128 fmind128(_Decimal128 x, _Decimal128 y); #endif
                            Description
 
N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E) 7.12.12.4 The fmaximum functions
Synopsis
1
2 The fmaximum functions determine the maximum value of their arguments. For these functions, +0 is considered greater than 0. These functions differ from the fmaximum_num functions only in their treatment of NaN arguments (see F.10.9.4, F.10.9.5).
Returns
3 The fmaximum functions return the maximum value of their arguments. 7.12.12.5 The fminimum functions
Synopsis
1
2 The fminimum functions determine the minimum value of their arguments. For these functions, 0 is considered less than +0. These functions differ from the fminimum_num functions only in their treatment of NaN arguments (see F.10.9.4, F.10.9.5).
Returns
3 The fminimum functions return the minimum value of their arguments. 7.12.12.6 The fmaximum_mag functions
Synopsis
1
2 The fmaximum_mag functions determine the value of the argument of maximum magnitude: x if |x| > |y|, y if |y| > |x|, and fmaximum(x, y) otherwise. These functions differ from the
fmaximum_mag_num functions only in their treatment of NaN arguments (see F.10.9.4, F.10.9.5).
§ 7.12.12.6 Library 273
         #include <math.h>
double fmaximum(double x, double y);
float fmaximumf(float x, float y);
long double fmaximuml(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 fmaximumd32(_Decimal32 x, _Decimal32 y); _Decimal64 fmaximumd64(_Decimal64 x, _Decimal64 y); _Decimal128 fmaximumd128(_Decimal128 x, _Decimal128 y); #endif
                                    Description
         #include <math.h>
double fminimum(double x, double y);
float fminimumf(float x, float y);
long double fminimuml(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 fminimumd32(_Decimal32 x, _Decimal32 y); _Decimal64 fminimumd64(_Decimal64 x, _Decimal64 y); _Decimal128 fminimumd128(_Decimal128 x, _Decimal128 y); #endif
                                    Description
         #include <math.h>
double fmaximum_mag(double x, double y);
float fmaximum_magf(float x, float y);
long double fmaximum_magl(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 fmaximum_magd32(_Decimal32 x, _Decimal32 y); _Decimal64 fmaximum_magd64(_Decimal64 x, _Decimal64 y); _Decimal128 fmaximum_magd128(_Decimal128 x, _Decimal128 y); #endif
                                    Description

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054 Returns
3 The fmaximum_mag functions return the value of the argument of maximum magnitude. 7.12.12.7 The fminimum_mag functions
Synopsis
1
        #include <math.h>
double fminimum_mag(double x, double y);
float fminimum_magf(float x, float y);
long double fminimum_magl(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 fminimum_magd32(_Decimal32 x, _Decimal32 y); _Decimal64 fminimum_magd64(_Decimal64 x, _Decimal64 y); _Decimal128 fminimum_magd128(_Decimal128 x, _Decimal128 y); #endif
                            Description
2 The fminimum_mag functions determine the value of the argument of minimum magnitude: x if |x| < |y|, y if |y| < |x|, and fminimum(x, y) otherwise. These functions differ from the
fminimum_mag_num functions only in their treatment of NaN arguments (see F.10.9.4, F.10.9.5). Returns
3 The fminimum_mag functions return the value of the argument of minimum magnitude. 7.12.12.8 The fmaximum_num functions
Synopsis
1
        #include <math.h>
double fmaximum_num(double x, double y);
float fmaximum_numf(float x, float y);
long double fmaximum_numl(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 fmaximum_numd32(_Decimal32 x, _Decimal32 y); _Decimal64 fmaximum_numd64(_Decimal64 x, _Decimal64 y); _Decimal128 fmaximum_numd128(_Decimal128 x, _Decimal128 y); #endif
                            Description
2 The fmaximum_num functions determine the maximum value of their numeric arguments. They determine the number if one argument is a number and the other is a NaN. These functions differ from the fmaximum functions only in their treatment of NaN arguments (see F.10.9.4, F.10.9.5).
Returns
3 The fmaximum_num functions return the maximum value of their numeric arguments. 7.12.12.9 The fminimum_num functions
Synopsis
1
        #include <math.h>
double fminimum_num(double x, double y);
float fminimum_numf(float x, float y);
long double fminimum_numl(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 fminimum_numd32(_Decimal32 x, _Decimal32 y); _Decimal64 fminimum_numd64(_Decimal64 x, _Decimal64 y); _Decimal128 fminimum_numd128(_Decimal128 x, _Decimal128 y); #endif
                            274
Library
§ 7.12.12.9

N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E) Description
2 The fminimum_num functions determine the minimum value of their numeric arguments. They determine the number if one argument is a number and the other is a NaN. These functions differ from the fminimum functions only in their treatment of NaN arguments (see F.10.9.4, F.10.9.5).
Returns
3 The fminimum_num functions return the minimum value of their numeric arguments. 7.12.12.10 The fmaximum_mag_num functions
Synopsis
1
2 The fmaximum_mag_num functions determine the value of a numeric argument of maximum mag- nitude. They determine the number if one argument is a number and the other is a NaN. These functions differ from the fmaximum_mag functions only in their treatment of NaN arguments (see F.10.9.4, F.10.9.5).
Returns
3 The fmaximum_mag_num functions return the value of a numeric argument of maximum magnitude. 7.12.12.11 The fminimum_mag_num functions
Synopsis
1
2 The fminimum_mag_num functions determine the value of a numeric argument of minimum mag- nitude. They determine the number if one argument is a number and the other is a NaN. These functions differ from the fminimum_mag functions only in their treatment of NaN arguments (see F.10.9.4, F.10.9.5).
Returns
3 The fminimum_mag_num functions return the value of a numeric argument of minimum magnitude.
         #include <math.h>
double fmaximum_mag_num(double x, double y);
float fmaximum_mag_numf(float x, float y);
long double fmaximum_mag_numl(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 fmaximum_mag_numd32(_Decimal32 x, _Decimal32 y); _Decimal64 fmaximum_mag_numd64(_Decimal64 x, _Decimal64 y); _Decimal128 fmaximum_mag_numd128(_Decimal128 x, _Decimal128 y); #endif
                                    Description
         #include <math.h>
double fminimum_mag_num(double x, double y);
float fminimum_mag_numf(float x, float y);
long double fminimum_mag_numl(long double x, long double y); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 fminimum_mag_numd32(_Decimal32 x, _Decimal32 y); _Decimal64 fminimum_mag_numd64(_Decimal64 x, _Decimal64 y); _Decimal128 fminimum_mag_numd128(_Decimal128 x, _Decimal128 y); #endif
                                    Description
7.12.13 7.12.13.1 Synopsis
1
Fused multiply-add The fma functions
         § 7.12.13.1
Library 275
#include <math.h>
double fma(double x, double y, double z);
    
ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054
    float fmaf(float x, float y, float z);
long double fmal(long double x, long double y, long double z); #ifdef __STDC_IEC_60559_DFP__
_Decimal32 fmad32(_Decimal32 x, _Decimal32 y, _Decimal32 z); _Decimal64 fmad64(_Decimal64 x, _Decimal64 y, _Decimal64 z); _Decimal128 fmad128(_Decimal128 x, _Decimal128 y, _Decimal128 z); #endif
                      Description
2 The fma functions compute (x × y) + z, rounded as one ternary operation: they compute the value (as if) to infinite precision and round once to the result format, according to the current rounding mode. A range error occurs for some finite arguments. A domain error occurs for some infinite arguments.
Returns
3 The fma functions return (x × y) + z, rounded as one ternary operation.
7.12.14 Functions that round result to narrower type
1 The functions in this subclause round their results to a type typically narrower300) than the parameter types.
7.12.14.1 Add and round to narrower type Synopsis
1
2 These functions compute the sum of x + y, rounded to the type of the function. They compute the sum (as if) to infinite precision and round once to the result format, according to the current rounding mode. A range error occurs for some finite arguments. A domain error may occur for infinite arguments.
Returns
3 These functions return the sum of x + y, rounded to the type of the function. 7.12.14.2 Subtract and round to narrower type
Synopsis
1
        #include <math.h>
float fadd(double x, double y);
float faddl(long double x, long double y);
double daddl(long double x, long double y);
#ifdef __STDC_IEC_60559_DFP__
_Decimal32 d32addd64(_Decimal64 x, _Decimal64 y); _Decimal32 d32addd128(_Decimal128 x, _Decimal128 y); _Decimal64 d64addd128(_Decimal128 x, _Decimal128 y); #endif
                            Description
        #include <math.h>
float fsub(double x, double y);
float fsubl(long double x, long double y);
double dsubl(long double x, long double y);
#ifdef __STDC_IEC_60559_DFP__
_Decimal32 d32subd64(_Decimal64 x, _Decimal64 y); _Decimal32 d32subd128(_Decimal128 x, _Decimal128 y); _Decimal64 d64subd128(_Decimal128 x, _Decimal128 y); #endif
                             300)In some cases the destination type might not be narrower than the parameter types. For example, double might not be narrower than long double.
276 Library § 7.12.14.2

N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E) Description
2 These functions compute the difference of x  y, rounded to the type of the function. They compute the difference (as if) to infinite precision and round once to the result format, according to the current rounding mode. A range error occurs for some finite arguments. A domain error may occur for infinite arguments.
Returns
3 These functions return the difference of x  y, rounded to the type of the function. 7.12.14.3 Multiply and round to narrower type
Synopsis
1
2 These functions compute the product x × y, rounded to the return type of the function. They compute the product (as if) to infinite precision and round once to the result format, according to the current rounding mode. A range error occurs for some finite arguments. A domain error occurs for one infinite argument and one zero argument.
Returns
3 These functions return the product of x × y, rounded to the return type of the function. 7.12.14.4 Divide and round to narrower type
Synopsis
1
2 These functions compute the quotient x ÷ y, rounded to the return type of the function. They compute the quotient (as if) to infinite precision and round once to the result format, according to the current rounding mode. A range error occurs for some finite arguments. A domain error occurs for either both arguments infinite or both arguments zero. A pole error occurs for a finite x and a zero y.
Returns
3 These functions return the quotient x ÷ y, rounded to the type of the function. 7.12.14.5 Fused multiply-add and round to narrower type
Synopsis
1
         #include <math.h>
float fmul(double x, double y);
float fmull(long double x, long double y);
double dmull(long double x, long double y);
#ifdef __STDC_IEC_60559_DFP__
_Decimal32 d32muld64(_Decimal64 x, _Decimal64 y); _Decimal32 d32muld128(_Decimal128 x, _Decimal128 y); _Decimal64 d64muld128(_Decimal128 x, _Decimal128 y); #endif
                                    Description
         #include <math.h>
float fdiv(double x, double y);
float fdivl(long double x, long double y);
double ddivl(long double x, long double y);
#ifdef __STDC_IEC_60559_DFP__
_Decimal32 d32divd64(_Decimal64 x, _Decimal64 y); _Decimal32 d32divd128(_Decimal128 x, _Decimal128 y); _Decimal64 d64divd128(_Decimal128 x, _Decimal128 y); #endif
                                    Description
         #include <math.h>
float ffma(double x, double y, double z);
    § 7.12.14.5 Library 277

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054
    float ffmal(long double x, long double y, long double z);
double dfmal(long double x, long double y, long double z);
#ifdef __STDC_IEC_60559_DFP__
_Decimal32 d32fmad64(_Decimal64 x, _Decimal64 y, _Decimal64 z); _Decimal32 d32fmad128(_Decimal128 x, _Decimal128 y, _Decimal128 z); _Decimal64 d64fmad128(_Decimal128 x, _Decimal128 y, _Decimal128 z); #endif
                      Description
2 These functions compute (x × y) + z, rounded to the return type of the function. They compute ( x × y) + z (as if) to infinite precision and round once to the result format, according to the current rounding mode. A range error occurs for some finite arguments. A domain error may occur for an infinite argument.
Returns
3 These functions return (x × y) + z, rounded to the return type of the function. 7.12.14.6 Square root rounded to narrower type
Synopsis
1
2 These functions compute the square root of x, rounded to the type of the function. They compute the square root (as if) to infinite precision and round once to the result format, according to the current rounding mode. A range error occurs for some finite positive arguments. A domain error occurs if the argument is less than zero.
Returns
3 These functions return the nonnegative square root of x, rounded to the return type of the function.
7.12.15 Quantum and quantum exponent functions 7.12.15.1 The quantizedN functions
Synopsis
1
2 The quantizedN functions compute, if possible, a value with the numerical value of x and the quantum exponent of y. If the quantum exponent is being increased, the value shall be correctly rounded; if the result does not have the same value as x, the "inexact" floating-point exception shall be raised. If the quantum exponent is being decreased and the significand of the result has more digits than the type would allow, the result is NaN, the "invalid" floating-point exception is raised, and a domain error occurs. If one or both operands are NaN the result is NaN. Otherwise if only one
        #include <math.h>
float fsqrt(double x);
float fsqrtl(long double x);
double dsqrtl(long double x);
#ifdef __STDC_IEC_60559_DFP__ _Decimal32 d32sqrtd64(_Decimal64 x); _Decimal32 d32sqrtd128(_Decimal128 x); _Decimal64 d64sqrtd128(_Decimal128 x); #endif
                            Description
        #include <math.h>
#ifdef __STDC_IEC_60559_DFP__
_Decimal32 quantized32(_Decimal32 x, _Decimal32 y); _Decimal64 quantized64(_Decimal64 x, _Decimal64 y); _Decimal128 quantized128(_Decimal128 x, _Decimal128 y); #endif
                   Description
278 Library § 7.12.15.1

N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E)
operand is infinite, the result is NaN, the "invalid" floating-point exception is raised, and a domain error occurs. If both operands are infinite, the result is DEC_INFINITY with the sign of x, converted to the type of the function. The quantizedN functions do not raise the "overflow" and "underflow" floating-point exceptions.
Returns
3 The quantizedN functions return a value with the numerical value of x (except for any rounding) and the quantum exponent of y.
7.12.15.2 The samequantumdN functions Synopsis
1
2 The samequantumdN functions determine if the quantum exponents of x and y are the same. If both x and y are NaN, or both infinite, they have the same quantum exponents; if exactly one operand is infinite or exactly one operand is NaN, they do not have the same quantum exponents. The samequantumdN functions raise no floating-point exception.
Returns
3 The samequantumdN functions return nonzero (true) when x and y have the same quantum expo- nents, zero (false) otherwise.
7.12.15.3 The quantumdN functions Synopsis
1
2 The quantumdN functions compute the quantum (5.2.4.2.3) of a finite argument. If x is infinite, the result is +.
Returns
3 The quantumdN functions return the quantum of x. 7.12.15.4 The llquantexpdN functions
Synopsis
1
         #include <math.h>
#ifdef __STDC_IEC_60559_DFP__
bool samequantumd32(_Decimal32 x, _Decimal32 y); bool samequantumd64(_Decimal64 x, _Decimal64 y); bool samequantumd128(_Decimal128 x, _Decimal128 y); #endif
                        Description
         #include <math.h>
#ifdef __STDC_IEC_60559_DFP__ _Decimal32 quantumd32(_Decimal32 x); _Decimal64 quantumd64(_Decimal64 x); _Decimal128 quantumd128(_Decimal128 x); #endif
                        Description
         #include <math.h>
#ifdef __STDC_IEC_60559_DFP__
long long int llquantexpd32(_Decimal32 x); long long int llquantexpd64(_Decimal64 x); long long int llquantexpd128(_Decimal128 x); #endif
                        § 7.12.15.4
Library 279

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054 Description
2 The llquantexpdN functions compute the quantum exponent (5.2.4.2.3) of a finite argument. If x is infinite or NaN, they compute LLONG_MIN, the "invalid" floating-point exception is raised, and a domain error occurs.
Returns
3 The llquantexpdN functions return the quantum exponent of x.
7.12.16 Decimal re-encoding functions
1 IEC 60559 specifies two different schemes to encode significands in the object representation of a decimal floating-point object: one based on decimal encoding (which packs three decimal digits into 10 bits), the other based on binary encoding (as a binary integer). An implementation may use either of these encoding schemes for its decimal floating types. The re-encoding functions in this subclause provide conversions between external decimal data with a given encoding scheme and the implementations corresponding decimal floating type.
7.12.16.1 The encodedecdN functions Synopsis
1
2 The encodedecdN functions convert *xptr into an IEC 60559 decimalN encoding in the encoding scheme based on decimal encoding of the significand and store the resulting encoding as an N/8 element array, with 8 bits per array element, in the object pointed to by encptr. The order of bytes in the array is implementation-defined. These functions preserve the value of *xptr and raise no floating-point exceptions. If *xptr is non-canonical, these functions may or may not produce a canonical encoding.
Returns
3 The encodedecdN functions return no value. 7.12.16.2 The decodedecdN functions
Synopsis
1
15
2 The decodedecdN functions interpret the N/8 element array pointed to by encptr as an IEC 60559
decimalN encoding, with 8 bits per array element, in the encoding scheme based on decimal 280 Library § 7.12.16.2
        #include <math.h>
#ifdef __STDC_IEC_60559_DFP__
void encodedecd32(unsigned char encptr[restrict static 4],
const _Decimal32*restrict xptr);
void encodedecd64(unsigned char encptr[restrict static 8],
const _Decimal64*restrict xptr);
void encodedecd128(unsigned char encptr[restrict static 16],
const _Decimal128*restrict xptr); #endif
                            Description
        #include <math.h>
#ifdef __STDC_IEC_60559_DFP__
void decodedecd32(_Decimal32 * restrict xptr,
const unsigned char encptr[restrict static 4]); void decodedecd64(_Decimal64 * restrict xptr,
const unsigned char encptr[restrict static 8]); void decodedecd128(_Decimal128 * restrict xptr,
const unsigned char encptr[restrict static 16]); #endif
                            Description

N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E)
encoding of the significand. The order of bytes in the array is implementation-defined. These functions convert the given encoding into a value of the decimal floating type, and store the result in the object pointed to by xptr. These functions preserve the encoded value and raise no floating-point exceptions. If the encoding is non-canonical, these functions may or may not produce a canonical representation.
Returns
3 The decodedecdN functions return no value. 7.12.16.3 The encodebindN functions
Synopsis
1
         #include <math.h>
#ifdef __STDC_IEC_60559_DFP__
void encodebind32(unsigned char encptr[restrict static 4],
const _Decimal32 * restrict xptr);
void encodebind64(unsigned char encptr[restrict static 8],
const _Decimal64 * restrict xptr);
void encodebind128(unsigned char encptr[restrict static 16],
const _Decimal128 * restrict xptr); #endif
                                    Description
2 The encodebindN functions convert *xptr into an IEC 60559 decimalN encoding in the encoding scheme based on binary encoding of the significand and store the resulting encoding as an N/8 element array, with 8 bits per array element, in the object pointed to by encptr. The order of bytes in the array is implementation-defined. These functions preserve the value of *xptr and raise no floating-point exceptions. If *xptr is non-canonical, these functions may or may not produce a canonical encoding.
Returns
3 The encodebindN functions return no value. 7.12.16.4 The decodebindN functions
Synopsis
1
         #include <math.h>
#ifdef __STDC_IEC_60559_DFP__
void decodebind32(_Decimal32 * restrict xptr,
const unsigned char encptr[restrict static 4]); void decodebind64(_Decimal64 * restrict xptr,
const unsigned char encptr[restrict static 8]); void decodebind128(_Decimal128 * restrict xptr,
const unsigned char encptr[restrict static 16]); #endif
                                    Description
2 The decodebindN functions interpret the N/8 element array pointed to by encptr as an IEC 60559 decimalN encoding, with 8 bits per array element, in the encoding scheme based on binary encoding of the significand. The order of bytes in the array is implementation-defined. These functions convert the given encoding into a value of decimal floating type, and store the result in the object pointed to by xptr. These functions preserve the encoded value and raise no floating-point exceptions. If the encoding is non-canonical, these functions may or may not produce a canonical representation.
Returns
3 The decodebindN functions return no value.
§ 7.12.16.4 Library 281

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054 7.12.17 Comparison macros
1 The relational and equality operators support the usual mathematical relationships between numeric values. For any ordered pair of numeric values exactly one of the relationships  less, greater, and equal  is true. Relational operators may raise the "invalid" floating-point exception when argument values are NaNs. For a NaN and a numeric value, or for two NaNs, just the unordered relationship is true.301) Subclauses 7.12.17.1 through 7.12.17.6 provide macros that are quiet versions of the relational operators: the macros do not raise the "invalid" floating-point exception as an effect of quiet NaN arguments. The comparison macros facilitate writing efficient code that accounts for quiet NaNs without suffering the "invalid" floating-point exception. In the synopses in this subclause, real-floating indicates that the argument shall be an expression of real floating type302) (both arguments need not have the same type).303) If either argument has decimal floating type, the other argument shall have decimal floating type as well.
7.12.17.1 The isgreater macro Synopsis
1
2 The isgreater macro determines whether its first argument is greater than its second argument. Thevalueofisgreater(x,y)isalwaysequalto(x)> (y);however,unlike(x)> (y),isgreater (x,y) does not raise the "invalid" floating-point exception when x and y are unordered and neither is a signaling NaN.
Returns
3 The isgreater macro returns the value of (x)> (y). 7.12.17.2 The isgreaterequal macro
Synopsis
1
2 The isgreaterequal macro determines whether its first argument is greater than or equal to its second argument. The value of isgreaterequal(x,y) is always equal to (x)>= (y); however, unlike (x)>= (y), isgreaterequal(x,y) does not raise the "invalid" floating-point exception when x and y are unordered and neither is a signaling NaN.
Returns
3 The isgreaterequal macro returns the value of (x)>= (y). 7.12.17.3 The isless macro
Synopsis
1
2 The isless macro determines whether its first argument is less than its second argument. The value of isless(x,y) is always equal to (x)< (y); however, unlike (x)< (y), isless(x,y) does not
301)IEC 60559 requires that the built-in relational operators raise the "invalid" floating-point exception if the operands compare unordered, as an error indicator for programs written without consideration of NaNs; the result in these cases is false.
302)If any argument is of integer type, or any other type that is not a real floating type, the behavior is undefined.
303) Whether an argument represented in a format wider than its semantic type is converted to the semantic type is unspecified.
        Description
   Description
Description
#include <math.h>
int isgreater(real-floating x, real-floating y);
            #include <math.h>
int isgreaterequal(real-floating x, real-floating y);
               #include <math.h>
int isless(real-floating x, real-floating y);
        282 Library § 7.12.17.3

N3054 working draft  September 3, 2022 ISO/IEC 9899:2023 (E) raise the "invalid" floating-point exception when x and y are unordered and neither is a signaling
NaN.
Returns
3 The isless macro returns the value of (x) < (y). 7.12.17.4 The islessequal macro
Synopsis
1
2 The islessequal macro determines whether its first argument is less than or equal to its second argument.Thevalueofislessequal(x,y)isalwaysequalto(x)<= (y);however,unlike(x)<= (y), islessequal(x,y) does not raise the "invalid" floating-point exception when x and y are
unordered and neither is a signaling NaN.
Returns
3 The islessequal macro returns the value of (x)<= (y). 7.12.17.5 The islessgreater macro
Synopsis
1
2 The islessgreater macro determines whether its first argument is less than or greater than its secondargument.Theislessgreater(x,y)macroissimilarto(x)< (y)|| (x)> (y);however, islessgreater(x,y) does not raise the "invalid" floating-point exception when x and y are un- ordered and neither is a signaling NaN (nor does it evaluate x and y twice).
               Description
             Description
#include <math.h>
int islessequal(real-floating x, real-floating y);
  #include <math.h>
int islessgreater(real-floating x, real-floating y);
    Returns
3 The islessgreater macro returns the value of (x)< 7.12.17.6 The isunordered macro
Synopsis
1
(y)|| (x)> (y).
         Description
#include <math.h>
int isunordered(real-floating x, real-floating y);
        2 The isunordered macro determines whether its arguments are unordered. It raises no floating-point exceptions if neither argument is a signaling NaN.
Returns
3 The isunordered macro returns 1 if its arguments are unordered and 0 otherwise. 7.12.17.7 The iseqsig macro
Synopsis
1
2 The iseqsig macro determines whether its arguments are equal. If an argument is a NaN, a domain error occurs for the macro, as if a domain error occurred for a function (7.12.1).
         Description
#include <math.h>
int iseqsig(real-floating x, real-floating y);
        § 7.12.17.7 Library 283

ISO/IEC 9899:2023 (E) working draft  September 3, 2022 N3054 Returns
3 The iseqsig macro returns 1 if its arguments are equal and 0 otherwise.

int main() {
//    PR3(st.a,st.b,st.c,d);
    printf("%s\n", n3054);
    return EXIT_SUCCESS;
}

編纂・実行結果(compile and go)

bash

検討事項(agenda)

コンパイルエラーを取るか、コンパイルエラーの理由を解説する。

応用例1 MISRA C/C++

MISRA C まとめ #include

MISRA C++ 5-0-16

応用例2 CERT C/C++

SEI CERT C++ Coding Standard AA. Bibliography 確認中。

MISRA C/C++, AUTOSAR C++, CERT C/C++とC/C++工業標準をコンパイルする

自己参考資料(self reference)

関連する自己参照以外は、こちらの先頭に移転。

C言語(C++)に対する誤解、曲解、無理解、爽快。

C2011コンパイル一覧@researchmap

https://researchmap.jp/jownvh0ye-1797580/#_1797580

[C][C++]の国際規格案の例題をコンパイルするときの課題7つ。

C Puzzle Bookの有り難み5つ、C言語規格及びCコンパイラの特性を認識

dockerにclang

docker gnu(gcc/g++) and llvm(clang/clang++)

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)

astyle 使ってみた

<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>

文書履歴(document history)

ver. 0.01 初稿  20221121
ver. 0.02 ありがとう追記 20230622

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0