Introduction to C programming/Simple math

C mathematical operations are functions in standard library of the C programming language implementing basic mathematical functions.All functions use numbers in one manner or another. Different C standards provide different sets of functions. Most of these functions are also available in the C++ standard library.

Overview of functions
Most of the mathematical functions are defined in  (  header in C++). The functions that operate on integers, such as,  ,  , and  , are instead defined in the   header (  header in C++).

Any functions that operate on angles use radians as the unit of angle instead of using degree like in normal practise.

Floating point environment
What is the FPU?

The FPU (Floating-Point Unit) is a unit within the CPU set up to perform math in floating point numbers. The reason this is done is, due to the different representations in memory, integral and floating-point numbers need a different physical operation to do math on them. An FPU should be able to addition, subtraction, multiplication and division (but not a modulo, due to problems with accuracy), among other operations, within a very small error margin.

Math with FPU

C99 adds several functions and types for fine-grained control of floating point environment. These functions can be used to control a variety of settings that affect floating-point computations, for example, the rounding mode, on what conditions exceptions occur, when numbers are flushed to zero, etc. The floating point environment functions and types are defined in  header (  in C++).

Complex numbers
C99 adds a new  keyword (and   convenience macro) that provides support for complex numbers. Any floating point type can be modified with, and is then defined as a pair of floating point numbers. Note that C99 and C++ do not implement complex numbers in a code-compatible way - the latter instead provides the class.

All operations on complex numbers are defined in  header. As with the real-valued functions, an  or   suffix denotes the   or   variant of the function.

A few more complex functions are "reserved for future use in C99". Implementations are provided by open-source projects that are not part of the standard library.

Type-generic functions
The header  defines a type-generic macro for each mathematical function defined in   and. This adds a limited support for function overloading of the mathematical functions: the same function name can be used with different types of parameters; the actual function will be selected at compile-time according to the types of the parameters.

Each type-generic macro that corresponds to a function that is defined for both real and complex numbers encapsulates a total of 6 different functions:,   and  , and their   variants. The type-generic macros that correspond to a function that is defined for only real numbers encapsulates a total of 3 different functions:,   and   variants of the function.

The C++ language includes native support for function overloading and thus does not provide the  header even as a compatibility feature.

Random number generation
The header  (  in C++) defines several functions that can be used for statistically random number generation.

The  family of random number functions are not defined in POSIX standard, but is found in some common   implementations. It used to refer to the keystream generator of a leaked version of RC4 cipher (hence "alleged RC4"), but different algorithms, usually from other ciphers like ChaCha20, have been implemented since using the same name.

The quality of randomness from  are usually too weak to be even considered statistically random, and it requires explicit seeding. It is usually advised to use  instead of   when possible. Some C libraries implement  using   internally.