openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
short_float.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) NumeriCor GmbH
2 // SPDX-License-Identifier: Apache-2.0
3 
5 // If automatically generated, keep above
6 // comment as first line in file.
7 #ifndef __SHORT_FLOAT_H__
8 #define __SHORT_FLOAT_H__
10 
11 /*
12 ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf
13 
14 Fast Half Float Conversions
15 Jeroen van der Zijp
16 November 2008
17 (Revised September 2010)
18 
19 Use the dumpTables code to generate the corresponding C file.
20 */
21 
22 
23 #include <cstdint>
24 
25 namespace opencarp {
26 
27 extern const uint16_t basetable[512];
28 extern const uint16_t shifttable[512];
29 extern const uint32_t mantissatable[2048];
30 extern const uint16_t offsettable[64];
31 extern const uint32_t exponenttable[64];
32 
33 typedef uint16_t short_float;
34 
35 static inline short_float shortFromFloat(const float external_ff) {
36  union {
37  float as_float;
38  uint32_t as_uint32;
39  } c;
40  c.as_float = external_ff;
41  return basetable[(c.as_uint32>>23)&0x1ff]+((c.as_uint32&0x007fffff)>>shifttable[(c.as_uint32>>23)&0x1ff]);
42 }
43 
44 static inline float floatFromShort(const short_float h) {
45  union {
46  float as_float;
47  uint32_t as_uint32;
48  } c;
49  c.as_uint32 = mantissatable[offsettable[h>>10]+(h&0x3ff)]+exponenttable[h>>10];
50  return c.as_float;
51 }
52 
53 #define SHORT_FLOAT_MACHINE_EPS 0.0009765625
54 
55 } // namespace opencarp
56 
58 #endif
const uint32_t mantissatable[2048]
const uint32_t exponenttable[64]
const uint16_t shifttable[512]
Definition: short_float.cc:523
uint16_t short_float
Definition: short_float.h:33
const uint16_t basetable[512]
Definition: short_float.cc:8
const uint16_t offsettable[64]
uint16_t short_float
Definition: short_float.h:58