acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
numeric.h
1//
2// as numeric Created by camilo on 2022-10-23 09:16 <3ThomasBorregaardSorensen!!
3//
4// as numerics Created by camilo on 2023-06-14 20:45 <3ThomasBorregaardSorensen!!
5#pragma once
6
7
8#include "numeric_info.h"
9
10
11namespace numeric // (?acme or ace, when I am going to introduce ace, on in the minimum insertion ace static library)
12{
13
14
15 template <typename T>
16 constexpr ::i32 sign(T val)
17 {
18
19 return ((val > ::numeric_info < T >::null()) ? 1 : 0)
20 - ((val < ::numeric_info < T >::null()) ? 1 : 0);
21
22 }
23
24
25 template <typename T>
26 ::i32 non_zero_sign(T val)
27 {
28 // val < 0 -> -1
29 // val >= 0 -> 1
30 return (::numeric_info < T >::null() <= val) - (val < ::numeric_info < T >::null());
31 }
32
33
34 template <typename T>
35 T& set_maximum(T& payload)
36 {
37
38 return payload = ::numeric_info < T >::maximum();
39
40 }
41
42 template <typename T>
43 T& set_minimum(T& payload)
44 {
45
46 return payload = ::numeric_info < T >::minimum();
47
48 }
49
50
51 template <typename T>
52 T& set_null(T& payload)
53 {
54
55 return payload = ::numeric_info < T >::null();
56
57 }
58
59
60 template <typename T>
61 T& set_unitary(T& payload)
62 {
63
64 return payload = ::numeric_info < T >::unitary();
65
66 }
67
68
69 template <typename T>
70 bool is_maximum(const T& payload)
71 {
72
73 return payload == ::numeric_info < T >::maximum();
74
75 }
76
77 template <typename T>
78 bool is_minimum(const T& payload)
79 {
80
81 return payload == ::numeric_info < T >::minimum();
82
83 }
84
85
86 template <typename T>
87 bool is_null(const T& payload)
88 {
89
90 return payload == ::numeric_info < T >::null();
91
92 }
93
94
95 template <typename T>
96 bool is_unitary(const T& payload)
97 {
98
99 return payload == ::numeric_info < T >::unitary();
100
101 }
102
103
104 inline ::f64 floor(::f64 f)
105 {
106
107 return ::floor(f);
108
109 }
110
111
112 inline ::f32 floor(::f32 f)
113 {
114
115 return ::floorf(f);
116
117 }
118
119
120 inline ::f64 ceil(::f64 f)
121 {
122
123 return ::ceil(f);
124
125 }
126
127
128 inline ::f32 ceil(::f32 f)
129 {
130
131 return ::ceilf(f);
132
133 }
134
135
136} // namespace numeric
137
138
139