A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/cmath/fpclassify/ below:

macro/function

<cmath> <ctgmath>

fpclassify function
int fpclassify (float x);int fpclassify (double x);int fpclassify (long double x);

Classify floating-point value

Returns a value of type int that matches one of the classification macro constants, depending on the value of x:

value description FP_INFINITE Positive or negative infinity (overflow) FP_NAN Not-A-Number FP_ZERO Value of zero FP_SUBNORMAL Sub-normal value (underflow) FP_NORMAL Normal value (none of the above) Note that each value pertains to a single category: zero is not a normal value.

These macro constants of type int are defined in header <cmath> (<math.h>).

In C, this is implemented as a macro, but the type of x shall be float, double or long double.


Parameters
x
The value to classify.

Return value One of the followoing int values: FP_INFINITE, FP_NAN, FP_ZERO, FP_SUBNORMAL or FP_NORMAL.

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* fpclassify example */
#include <stdio.h>      /* printf */
#include <math.h>       /* fpclassify, signbit, FP_* */

int main()
{
  double d = 1.0 / 0.0;
  switch (fpclassify(d)) {
    case FP_INFINITE:  printf ("infinite");  break;
    case FP_NAN:       printf ("NaN");       break;
    case FP_ZERO:      printf ("zero");      break;
    case FP_SUBNORMAL: printf ("subnormal"); break;
    case FP_NORMAL:    printf ("normal");    break;
  }
  if (signbit(d)) printf (" negative\n");
  else printf (" positive or unsigned\n");
  return 0;
}

Output:
infinite positive or unsigned


See also
isfinite
Is finite value (macro)
isnan
Is Not-A-Number (macro/function)
isnormal
Is normal (macro/function)
signbit
Sign bit (macro/function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4