GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • TUTORIALS
  • REFERENCE
  • ARTICLES
  • FORUM
  • C library:
  • <cassert> (assert.h)
  • <cctype> (ctype.h)
  • <cerrno> (errno.h)
  • <cfenv> (fenv.h)
  • <cfloat> (float.h)
  • <cinttypes> (inttypes.h)
  • <ciso646> (iso646.h)
  • <climits> (limits.h)
  • <clocale> (locale.h)

This view

  • Original page
  • New address

GeezerVison is showing cplusplus.com — fpclassify

  • TUTORIALS
  • REFERENCE
  • ARTICLES
  • FORUM

C++

  • Tutorials
  • Reference
  • Articles
  • Forum

Reference

  • C library:

    • <cassert> (assert.h)
    • <cctype> (ctype.h)
    • <cerrno> (errno.h)
    • C++11
      <cfenv> (fenv.h)
    • <cfloat> (float.h)
    • C++11
      <cinttypes> (inttypes.h)
    • <ciso646> (iso646.h)
    • <climits> (limits.h)
    • <clocale> (locale.h)
    • <cmath> (math.h)
    • <csetjmp> (setjmp.h)
    • <csignal> (signal.h)
    • <cstdarg> (stdarg.h)
    • C++11
      <cstdbool> (stdbool.h)
    • <cstddef> (stddef.h)
    • C++11
      <cstdint> (stdint.h)
    • <cstdio> (stdio.h)
    • <cstdlib> (stdlib.h)
    • <cstring> (string.h)
    • C++11
      <ctgmath> (tgmath.h)
    • <ctime> (time.h)
    • C++11
      <cuchar> (uchar.h)
    • <cwchar> (wchar.h)
    • <cwctype> (wctype.h)
  • Containers:

    • C++11
      <array>
    • <deque>
    • C++11
      <forward_list>
    • <list>
    • <map>
    • <queue>
    • <set>
    • <stack>
    • C++11
      <unordered_map>
    • C++11
      <unordered_set>
    • <vector>
  • Input/Output:

    • <fstream>
    • <iomanip>
    • <ios>
    • <iosfwd>
    • <iostream>
    • <istream>
    • <ostream>
    • <sstream>
    • <streambuf>
  • Multi-threading:

    • C++11
      <atomic>
    • C++11
      <condition_variable>
    • C++11
      <future>
    • C++11
      <mutex>
    • C++11
      <thread>
  • Other:

    • <algorithm>
    • <bitset>
    • C++11
      <chrono>
    • C++11
      <codecvt>
    • <complex>
    • <exception>
    • <functional>
    • C++11
      <initializer_list>
    • <iterator>
    • <limits>
    • <locale>
    • <memory>
    • <new>
    • <numeric>
    • C++11
      <random>
    • C++11
      <ratio>
    • C++11
      <regex>
    • <stdexcept>
    • <string>
    • C++11
      <system_error>
    • C++11
      <tuple>
    • C++11
      <type_traits>
    • C++11
      <typeindex>
    • <typeinfo>
    • <utility>
    • <valarray>

<cmath> (math.h)

  • functions

    • abs
    • acos
    • C++11
      acosh
    • asin
    • C++11
      asinh
    • atan
    • atan2
    • C++11
      atanh
    • C++11
      cbrt
    • ceil
    • C++11
      copysign
    • cos
    • cosh
    • C++11
      erf
    • C++11
      erfc
    • exp
    • C++11
      exp2
    • C++11
      expm1
    • fabs
    • C++11
      fdim
    • floor
    • C++11
      fma
    • C++11
      fmax
    • C++11
      fmin
    • fmod
    • C++11
      fpclassify
    • frexp
    • C++11
      hypot
    • C++11
      ilogb
    • C++11
      isfinite
    • C++11
      isgreater
    • C++11
      isgreaterequal
    • C++11
      isinf
    • C++11
      isless
    • C++11
      islessequal
    • C++11
      islessgreater
    • C++11
      isnan
    • C++11
      isnormal
    • C++11
      isunordered
    • ldexp
    • C++11
      lgamma
    • C++11
      llrint
    • C++11
      llround
    • log
    • log10
    • C++11
      log1p
    • C++11
      log2
    • C++11
      logb
    • C++11
      lrint
    • C++11
      lround
    • modf
    • C++11
      nan
    • C++11
      nanf
    • C++11
      nanl
    • C++11
      nearbyint
    • C++11
      nextafter
    • C++11
      nexttoward
    • pow
    • C++11
      remainder
    • C++11
      remquo
    • C++11
      rint
    • C++11
      round
    • C++11
      scalbln
    • C++11
      scalbn
    • C++11
      signbit
    • sin
    • sinh
    • sqrt
    • tan
    • tanh
    • C++11
      tgamma
    • C++11
      trunc
  • macro constants

    • HUGE_VAL
    • C++11
      HUGE_VALF
    • C++11
      HUGE_VALL
    • C++11
      INFINITY
    • C++11
      math_errhandling
    • NAN
  • types

    • C++11
      double_t
    • float_t
  • Reference
  • <cmath>
  • fpclassify
macro/function
<cmath> <ctgmath>

fpclassify

macro
fpclassify(x)
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:

valuedescription
FP_INFINITEPositive or negative infinity (overflow)
FP_NANNot-A-Number
FP_ZEROValue of zero
FP_SUBNORMALSub-normal value (underflow)
FP_NORMALNormal 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.
In C++, it is implemented with function overloads for each floating-point type.

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)
Home page | Privacy policy
© cplusplus.com, 2000-2026 - All rights reserved - v3.3.4s
Spotted an error? contact us
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.