openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
numerics
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 licensed under the openCARP Academic Public License (APL)
7
// v1.0: You can use and redistribute it and/or modify it in non-commercial
8
// academic environments under the terms of APL as published by the openCARP
9
// project v1.0, or (at your option) any later version. Commercial use requires
10
// a commercial license (info@opencarp.org).
11
//
12
// This program is distributed without any warranty; see the openCARP APL for
13
// more details.
14
//
15
// You should have received a copy of the openCARP APL along with this program
16
// and can find it online: http://www.opencarp.org/license
17
// ----------------------------------------------------------------------------
18
20
// If automatically generated, keep above
21
// comment as first line in file.
22
#ifndef __SHORT_FLOAT_H__
23
#define __SHORT_FLOAT_H__
24
26
/*
27
ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf
28
29
Fast Half Float Conversions
30
Jeroen van der Zijp
31
November 2008
32
(Revised September 2010)
33
34
Use the dumpTables code to generate the corresponding C file.
35
*/
36
37
38
#include <cstdint>
39
40
namespace
opencarp
{
41
42
extern
const
uint16_t
basetable
[512];
43
extern
const
uint16_t
shifttable
[512];
44
extern
const
uint32_t
mantissatable
[2048];
45
extern
const
uint16_t
offsettable
[64];
46
extern
const
uint32_t
exponenttable
[64];
47
48
typedef
uint16_t
short_float
;
49
50
static
inline
short_float shortFromFloat(
const
float
external_ff) {
51
union
{
52
float
as_float;
53
uint32_t as_uint32;
54
} c;
55
c.as_float = external_ff;
56
return
basetable[(c.as_uint32>>23)&0x1ff]+((c.as_uint32&0x007fffff)>>shifttable[(c.as_uint32>>23)&0x1ff]);
57
}
58
59
static
inline
float
floatFromShort(
const
short_float h) {
60
union
{
61
float
as_float;
62
uint32_t as_uint32;
63
} c;
64
c.as_uint32 = mantissatable[offsettable[h>>10]+(h&0x3ff)]+exponenttable[h>>10];
65
return
c.as_float;
66
}
67
68
#define SHORT_FLOAT_MACHINE_EPS 0.0009765625
69
70
}
// namespace opencarp
71
73
#endif
74
opencarp::offsettable
const uint16_t offsettable[64]
Definition:
short_float.cc:3104
opencarp::short_float
uint16_t short_float
Definition:
short_float.h:48
opencarp
Definition:
async_io.cc:33
opencarp::basetable
const uint16_t basetable[512]
Definition:
short_float.cc:23
opencarp::exponenttable
const uint32_t exponenttable[64]
Definition:
short_float.cc:3171
opencarp::mantissatable
const uint32_t mantissatable[2048]
Definition:
short_float.cc:1053
opencarp::shifttable
const uint16_t shifttable[512]
Definition:
short_float.cc:538
Generated by
1.8.13