fiber
Loading...
Searching...
No Matches
math.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4#include <cinttypes>
5#include <cstddef>
6#include <bit>
7
8namespace fiber{
9
10
11 template <typename Int, typename std::enable_if<std::is_integral<Int>::value, int>::type = 0>
12 constexpr Int pow(const Int base, const unsigned int exponent){
13 Int result = 1;
14 for(unsigned int i = 0; i < exponent; ++i){result *= base;}
15 return result;
16 }
17
21 constexpr std::size_t string_length(const char* str){
22 std::size_t i = 0;
23 for(;;++i, (void)++str){
24 if(*str == '\0') return i;
25 }
26 return i;
27 }
28
29 float frexp10(float value, int* exp10_out);
30
31 inline bool is_nan(float value) {
32 union { float f; uint32_t i; } u = { value };
33 return ((u.i & 0x7F800000) == 0x7F800000) && ((u.i & 0x007FFFFF) != 0);
34 }
35
36 inline bool is_pinf(float value) {
37 union { float f; uint32_t i; } u = { value };
38 return u.i == 0x7F800000;
39 }
40
41 inline bool is_ninf(float value) {
42 union { float f; uint32_t i; } u = { value };
43 return u.i == 0xFF800000;
44 }
45
46 inline bool is_inf(float value){
47 return is_pinf(value) || is_ninf(value);
48 }
49
50
51
52}
Definition Duration.hpp:17
bool is_pinf(float value)
Definition math.hpp:36
bool is_nan(float value)
Definition math.hpp:31
bool is_inf(float value)
Definition math.hpp:46
constexpr std::size_t string_length(const char *str)
returns the length of a terminated c-style string
Definition math.hpp:21
float frexp10(float value, int *exp10_out)
Definition math.cpp:5
bool is_ninf(float value)
Definition math.hpp:41
constexpr Int pow(const Int base, const unsigned int exponent)
Definition math.hpp:12