Math | wxWidgets

| Version: 3.2.11

Loading...
Searching...
No Matches
Functions
Math
Functions and Macros by Category

## Detailed Description

The functions in this section are typically related with math operations and floating point numbers.

## Functions
int | wxFinite (double x)
| Returns a non-zero value if x is neither infinite nor NaN (not a number), returns 0 otherwise.
unsigned int | wxGCD (unsigned int u, unsigned int v)
| Returns the greatest common divisor of the two given numbers.
bool | wxIsNaN (double x)
| Returns a non-zero value if x is NaN (not a number), returns 0 otherwise.
wxFloat64 | wxConvertFromIeeeExtended (const wxInt8 *bytes)
| Converts the given array of 10 bytes (corresponding to 80 bits) to a float number according to the IEEE floating point standard format (aka IEEE standard 754).
void | wxConvertToIeeeExtended (wxFloat64 num, wxInt8 *bytes)
| Converts the given floating number num in a sequence of 10 bytes which are stored in the given array bytes (which must be large enough) according to the IEEE floating point standard format (aka IEEE standard 754).
double | wxDegToRad (double deg)
| Convert degrees to radians.
double | wxRadToDeg (double rad)
| Convert radians to degrees.
unsigned int | wxCTZ (wxUint32 x)
| Count the number of trailing zeros.
template<typename T>
int | wxRound (T x)
| Small wrapper around std::lround().
bool | wxIsSameDouble (double x, double y)
| Returns true if both double values are identical.
bool | wxIsNullDouble (double x)
| Return true of x is exactly zero.
int | wxMulDivInt32 (int n, int numerator, int denominator)
| Computes the product of a number with a fraction with rounding.

## Function Documentation

## ◆ wxConvertFromIeeeExtended()

wxFloat64 wxConvertFromIeeeExtended | ( | const wxInt8 * | bytes | ) |

Converts the given array of 10 bytes (corresponding to 80 bits) to a float number according to the IEEE floating point standard format (aka IEEE standard 754).

See also
  wxConvertToIeeeExtended() to perform the opposite operation

## ◆ wxConvertToIeeeExtended()

void wxConvertToIeeeExtended | ( | wxFloat64 | num,
|  | wxInt8 * | bytes )

Converts the given floating number num in a sequence of 10 bytes which are stored in the given array bytes (which must be large enough) according to the IEEE floating point standard format (aka IEEE standard 754).

See also
  wxConvertFromIeeeExtended() to perform the opposite operation

## ◆ wxCTZ()

unsigned int wxCTZ | ( | wxUint32 | x | ) |

Count the number of trailing zeros.

This function returns the number of trailing zeros in the binary notation of its argument x. E.g. for x equal to 4, or 0b100, the return value is 2.

Parameters

  x | Strictly positive, i.e. non-zero, 32 bit number.

Since
  3.1.2

## ◆ wxDegToRad()

double wxDegToRad | ( | double | deg | ) |

Convert degrees to radians.

This function simply returns its argument multiplied by `M_PI/180` but is more readable than writing this expression directly.

See also
  wxRadToDeg()

Since
  3.1.0

## ◆ wxFinite()

int wxFinite | ( | double | x | ) |

Returns a non-zero value if x is neither infinite nor NaN (not a number), returns 0 otherwise.

Include file:

    #include <wx/math.h>

## ◆ wxGCD()

unsigned int wxGCD | ( | unsigned int | u,
|  | unsigned int | v )

Returns the greatest common divisor of the two given numbers.

Since
  3.1.0

Include file:

    #include <wx/math.h>

## ◆ wxIsNaN()

bool wxIsNaN | ( | double | x | ) |

Returns a non-zero value if x is NaN (not a number), returns 0 otherwise.

Include file:

    #include <wx/math.h>

## ◆ wxIsNullDouble()

bool wxIsNullDouble | ( | double | x | ) |

Return true of x is exactly zero.

This is only reliable if it has been assigned 0.

## ◆ wxIsSameDouble()

bool wxIsSameDouble | ( | double | x,
|  | double | y )

Returns true if both double values are identical.

This is only reliable if both values have been assigned the same value.

## ◆ wxMulDivInt32()

int wxMulDivInt32 | ( | int | n,
|  | int | numerator,
|  | int | denominator )

Computes the product of a number with a fraction with rounding.

This function returns `n*numerator/denominator` rounding the result. It is similar to the standard Win32 `MulDiv()` function and, in fact, is implemented by calling it under MSW, where `wx/msw/wrapwin.h` must be included in addition to `wx/math.h` for it to be used.

## ◆ wxRadToDeg()

double wxRadToDeg | ( | double | rad | ) |

Convert radians to degrees.

This function simply returns its argument multiplied by `180/M_PI` but is more readable than writing this expression directly.

See also
  wxDegToRad()

Since
  3.1.0

## ◆ wxRound()

template<typename T>

int wxRound | ( | T | x | ) |

Small wrapper around std::lround().

This function exists for compatibility, as it was more convenient than std::round() before C++11. Use std::lround() in the new code.

It is defined for all floating point types `T` and can be also used with integer types for compatibility, but such use is deprecated – simply remove the calls to wxRound() from your code if you're using it with integer types, it is unnecessary in this case.