#include <cmath>
#include <limits>
#include <stdexcept>
Go to the source code of this file.
◆ DivideRoundUp()
T DivideRoundUp |
( |
T |
dividend, |
|
|
T |
divisor |
|
) |
| |
low-level aka "lib"
this codebase was grown from modules shared between several projects, i.e. my personal library; hence the name "lib". it has been expanded to fit the needs of 0ad - in particular, resource loading.
owing to the dual-use situation, the 0ad coding conventions are not met; also, major changes are ill-advised because they may break other projects.
design goals
- fast and low-overhead, including startup time
- portable: must run on Win32, Mac OS X and Linux
- reusable across projects, i.e. no dependency on a central 'manager' that ties modules together.
scope
- POSIX definitions
- resource management
- debugging tools (including memory tracker)
- low-level helper functions, e.g. ADTs, endian conversion and timing
- platform-dependent system/feature detection
◆ feq()
bool feq |
( |
double |
d1, |
|
|
double |
d2, |
|
|
double |
epsilon = 0.00001 |
|
) |
| |
|
inline |
are the given floats nearly "equal"?
- Returns
- whether the numbers are within "epsilon" of each other.
notes:
- the epsilon magic number varies with the magnitude of the inputs. we use a sane default, but don't use this routine for very large/small comparands.
- floating-point numbers don't magically lose precision. addition, subtraction and multiplication results are precise up to the mantissa's least-significant bit. only division, sqrt, sin/cos and other transcendental operations introduce error.
◆ feqf()
bool feqf |
( |
float |
f1, |
|
|
float |
f2, |
|
|
float |
epsilon = 0.001f |
|
) |
| |
|
inline |
◆ IsSimilarMagnitude()
bool IsSimilarMagnitude |
( |
double |
d1, |
|
|
double |
d2, |
|
|
const double |
relativeErrorTolerance = 0.05 |
|
) |
| |
|
inline |
◆ u16_from_double()
u16 u16_from_double |
( |
double |
in | ) |
|
convert double to u16; verifies number is in range.
◆ u16_from_larger()
u16 u16_from_larger |
( |
T |
x | ) |
|
◆ u32_from_larger()
u32 u32_from_larger |
( |
T |
x | ) |
|
◆ u32_from_u16()
◆ u32_hi()
◆ u32_lo()
◆ u64_from_u32()
◆ u64_hi()
◆ u64_lo()
◆ u8_from_double()
u8 u8_from_double |
( |
double |
in | ) |
|
convert double to u8; verifies number is in range.
◆ u8_from_larger()