Namespaces
Variants

nan, nanf, nanl, nand32, nand64, nand128

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
nan nanf nanl nand N
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
Definiert in Header <math.h>
float nanf ( const char * arg ) ;
(1) (seit C99)
double nan ( const char * arg ) ;
(2) (seit C99)
long double nanl ( const char * arg ) ;
(3) (seit C99)
_Decimal32  nand32 ( const char * arg ) ;
(4) (seit C23)
_Decimal64  nand64 ( const char * arg ) ;
(5) (seit C23)
_Decimal128 nand128 ( const char * arg ) ;
(6) (seit C23)

Konvertiert die implementierungsdefinierte Zeichenkette arg in den entsprechenden stillen NaN-Wert, als ob die entsprechende Parsing-Funktion strtoX aufgerufen würde, wie folgt:

  • Der Aufruf nan ( "n-char-sequence" ) , wobei n-char-sequence eine Folge von Ziffern, lateinischen Buchstaben und Unterstrichen ist, entspricht dem Aufruf /*strtoX*/ ( "NAN(n-char-sequence)" , ( char ** ) NULL ) ; .
  • Der Aufruf nan ( "" ) entspricht dem Aufruf /*strtoX*/ ( "NAN()" , ( char ** ) NULL ) ; .
  • Der Aufruf nan ( "string" ) , wobei string weder eine n-char-sequence noch eine leere Zeichenkette ist, entspricht dem Aufruf /*strtoX*/ ( "NAN" , ( char ** ) NULL ) ; .
1) Die Parsing-Funktion ist strtof .
2) Die Parsing-Funktion ist strtod .
3) Die Parsing-Funktion ist strtold .
4) Die Parsing-Funktion ist strtod32 .
5) Die Parsing-Funktion ist strtod64 .
6) Die Parsing-Funktion ist strtod128 .

Die Funktionen, die Dezimal-Gleitkommawerte zurückgeben, werden genau dann deklariert, wenn die Implementierung __STDC_IEC_60559_DFP__ vordefiniert (d.h. die Implementierung unterstützt Dezimal-Gleitkommazahlen).

(seit C23)

Inhaltsverzeichnis

Parameter

arg - schmale Zeichenkette, die den Inhalt eines NaN identifiziert

Rückgabewert

Der stille NaN-Wert, der der identifizierenden Zeichenkette arg entspricht, oder null, falls die Implementierung keine stillen NaNs unterstützt.

Wenn die Implementierung IEEE-Gleitkommaarithmetik (IEC 60559) unterstützt, unterstützt sie auch stille NaNs.

Fehlerbehandlung

Diese Funktion unterliegt keinen der in math_errhandling spezifizierten Fehlerbedingungen.

Beispiel

#include <stdio.h>
#include <math.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
int main(void)
{
    double f1 = nan("1");
    uint64_t f1n; memcpy(&f1n, &f1, sizeof f1);
    printf("nan(\"1\")   = %f (%" PRIx64 ")\n", f1, f1n);
    double f2 = nan("2");
    uint64_t f2n; memcpy(&f2n, &f2, sizeof f2);
    printf("nan(\"2\")   = %f (%" PRIx64 ")\n", f2, f2n);
    double f3 = nan("0xF");
    uint64_t f3n; memcpy(&f3n, &f3, sizeof f3);
    printf("nan(\"0xF\") = %f (%" PRIx64 ")\n", f3, f3n);
}

Mögliche Ausgabe:

nan("1")   = nan (7ff8000000000001)
nan("2")   = nan (7ff8000000000002)
nan("0xF") = nan (7ff800000000000f)

Referenzen

  • C17-Standard (ISO/IEC 9899:2018):
  • 7.12.11.2 Die nan-Funktionen (S. 186-187)
  • F.10.8.2 Die nan-Funktionen (S. 386)
  • C11-Standard (ISO/IEC 9899:2011):
  • 7.12.11.2 Die nan-Funktionen (S. 256)
  • F.10.8.2 Die nan-Funktionen (S. 529)
  • C99-Standard (ISO/IEC 9899:1999):
  • 7.12.11.2 The nan functions (p: 237)
  • F.9.8.2 The fabs functions (p: 465)

Siehe auch

(C99)
prüft, ob die gegebene Zahl NaN ist
(Funktionsmakro)
(C99)
ergibt ein stilles NaN vom Typ float
(Makrokonstante)
C++-Dokumentation für nanf , nan , nanl