The spica renderer
Main Page
Modules
Classes
Files
File List
sources
core
float.h
1
#ifdef _MSC_VER
2
#pragma once
3
#endif
4
5
#ifndef _SPICA_FLOAT_H_
6
#define _SPICA_FLOAT_H_
7
8
#include <cmath>
9
#include <cstring>
10
11
inline
decltype(
auto
) floatToBits(
double
d) {
12
unsigned
long
long
ret;
13
memcpy(&ret, &d,
sizeof
(
double
));
14
return
ret;
15
}
16
17
inline
decltype(
auto
) bitsToFloat(
unsigned
long
long
bits) {
18
double
ret;
19
memcpy(&ret, &bits,
sizeof
(
double
));
20
return
ret;
21
}
22
23
inline
decltype(
auto
) nextFloatUp(
double
d) {
24
if
(std::isinf(d) && d > 0.0)
return
d;
25
if
(d == -0.0f) d = 0.0f;
26
auto
ui = floatToBits(d);
27
if
(d > 0.0) {
28
ui++;
29
}
else
{
30
ui--;
31
}
32
return
bitsToFloat(ui);
33
}
34
35
inline
decltype(
auto
) nextFloatDown(
double
d) {
36
if
(std::isinf(d) && d > 0.0)
return
d;
37
if
(d == -0.0f) d = 0.0f;
38
auto
ui = floatToBits(d);
39
if
(d > 0.0) {
40
ui--;
41
}
else
{
42
ui++;
43
}
44
return
bitsToFloat(ui);
45
}
46
47
#endif // _SPICA_FLOAT_H_
Generated by
1.8.6