File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -73,19 +73,25 @@ namespace gf {
73
73
template <typename T>
74
74
std::enable_if_t <std::is_floating_point_v<T>, T> compute_uniform_float ()
75
75
{
76
- return static_cast <T>(compute_raw_float ());
76
+ if constexpr (std::is_same_v<T, double >) {
77
+ return compute_raw_double ();
78
+ } else if constexpr (std::is_same_v<T, float >) {
79
+ return compute_raw_float ();
80
+ } else {
81
+ return static_cast <T>(compute_raw_float ());
82
+ }
77
83
}
78
84
79
85
template <typename T>
80
86
std::enable_if_t <std::is_floating_point_v<T>, T> compute_uniform_float (T max)
81
87
{
82
- return static_cast <T>(compute_raw_float ( ) * max) ;
88
+ return compute_uniform_float <T>() * max;
83
89
}
84
90
85
91
template <typename T>
86
92
std::enable_if_t <std::is_floating_point_v<T>, T> compute_uniform_float (T min, T max)
87
93
{
88
- return min + static_cast <T>(compute_raw_float ( ) * (max - min) );
94
+ return min + compute_uniform_float <T>() * (max - min);
89
95
}
90
96
91
97
template <typename T>
@@ -119,7 +125,8 @@ namespace gf {
119
125
}
120
126
121
127
uint64_t compute_raw_integer (uint64_t max);
122
- double compute_raw_float ();
128
+ double compute_raw_double ();
129
+ float compute_raw_float ();
123
130
124
131
private:
125
132
RandomEngine m_engine;
Original file line number Diff line number Diff line change @@ -220,10 +220,16 @@ namespace gf {
220
220
return r;
221
221
}
222
222
223
- double Random::compute_raw_float ()
223
+ double Random::compute_raw_double ()
224
224
{
225
225
const uint64_t value = m_engine ();
226
226
return double (value >> 11 ) * 0x1 .0p-53 ;
227
227
}
228
228
229
+ float Random::compute_raw_float ()
230
+ {
231
+ const uint64_t value = m_engine ();
232
+ return float (value >> 40 ) * 0x1 .0p-24f ;
233
+ }
234
+
229
235
} // namespace gf
You can’t perform that action at this time.
0 commit comments