Z / libzlang 0.29.0
C99 runtime library and the Zlang 0.29 source-to-source compiler
Loading...
Searching...
No Matches
generate_float32.h
Go to the documentation of this file.
1#ifndef ZLANG_STANDARD_RANDOM_GENERATE_FLOAT32_H
2#define ZLANG_STANDARD_RANDOM_GENERATE_FLOAT32_H
3
5
6#include <math.h>
7
9 float from, float to) {
10 if (from > to || !isfinite(from) || !isfinite(to)) {
12 return 0.0F;
13 }
14 const double _range_k = (double)to - (double)from;
15 if (!isfinite(_range_k)) {
17 return 0.0F;
18 }
19 const double _fraction_k = (double)zlang_std_random_next_u32(context) / 4294967296.0;
20 return (float)((double)from + (_range_k * _fraction_k));
21}
22
23#endif /* ZLANG_STANDARD_RANDOM_GENERATE_FLOAT32_H */
ZLANG_STATIC_INLINE float zlang_std_random_generate_float32(zlang_runtime_context_t *context, float from, float to)
Definition generate_float32.h:8
#define ZLANG_STATIC_INLINE
Definition inline.h:9
ZLANG_STATIC_INLINE uint32_t zlang_std_random_next_u32(zlang_runtime_context_t *context)
Definition state.h:29
ZLANG_STATIC_INLINE void zlang_std_random_trap_invalid_argument(void)
Definition state.h:19
Definition context.h:8