openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
tools
igbutils
short_float.h
Go to the documentation of this file.
1
// ----------------------------------------------------------------------------
2
// openCARP is an open cardiac electrophysiology simulator.
3
//
4
// Copyright (C) 2020 openCARP project
5
//
6
// This program is free software: you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published by
8
// the Free Software Foundation, either version 3 of the License, or
9
// (at your option) any later version.
10
//
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
15
//
16
// You should have received a copy of the GNU General Public License
17
// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
// ----------------------------------------------------------------------------
19
20
22
// If automatically generated, keep above
23
// comment as first line in file.
24
#ifndef __SHORT_FLOAT_H__
25
#define __SHORT_FLOAT_H__
26
28
/*
29
ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf
30
31
Fast Half Float Conversions
32
Jeroen van der Zijp
33
November 2008
34
(Revised September 2010)
35
36
Use the dumpTables code to generate the corresponding C file.
37
*/
38
39
40
#include <cstdint>
41
42
43
extern
const
uint16_t
basetable
[512];
44
extern
const
uint16_t
shifttable
[512];
45
extern
const
uint32_t
mantissatable
[2048];
46
extern
const
uint16_t
offsettable
[64];
47
extern
const
uint32_t
exponenttable
[64];
48
49
typedef
uint16_t
short_float
;
50
51
static
inline
short_float
shortFromFloat(
const
float
external_ff) {
52
union
{
53
float
as_float;
54
uint32_t as_uint32;
55
} c;
56
c.as_float = external_ff;
57
return
basetable
[(c.as_uint32>>23)&0x1ff]+((c.as_uint32&0x007fffff)>>
shifttable
[(c.as_uint32>>23)&0x1ff]);
58
}
59
60
static
inline
float
floatFromShort(
const
short_float
h) {
61
union
{
62
float
as_float;
63
uint32_t as_uint32;
64
} c;
65
c.as_uint32 =
mantissatable
[
offsettable
[h>>10]+(h&0x3ff)]+
exponenttable
[h>>10];
66
return
c.as_float;
67
}
68
69
#define SHORT_FLOAT_MACHINE_EPS 0.0009765625
70
72
#endif
73
mantissatable
const uint32_t mantissatable[2048]
Definition:
short_float.cc:1053
short_float
uint16_t short_float
Definition:
short_float.h:49
offsettable
const uint16_t offsettable[64]
Definition:
short_float.cc:3104
basetable
const uint16_t basetable[512]
Definition:
short_float.cc:23
shifttable
const uint16_t shifttable[512]
Definition:
short_float.cc:538
exponenttable
const uint32_t exponenttable[64]
Definition:
short_float.cc:3171
Generated by
1.8.13