GCC Code Coverage Report
Directory: . Exec Total Coverage
File: build-coverage/deps/include/symfpu/core/classify.h Lines: 21 21 100.0 %
Date: 2021-05-22 Branches: 38 64 59.4 %

Line Exec Source
1
/*
2
** Copyright (C) 2018 Martin Brain
3
**
4
** See the file LICENSE for licensing information.
5
*/
6
7
/*
8
** classify.h
9
**
10
** Martin Brain
11
** martin.brain@cs.ox.ac.uk
12
** 21/08/14
13
**
14
** The classification functions for different classes of float.
15
**
16
*/
17
18
#include "symfpu/core/unpackedFloat.h"
19
20
#ifndef SYMFPU_CLASSIFY
21
#define SYMFPU_CLASSIFY
22
23
namespace symfpu {
24
25
template <class t>
26
43
  typename t::prop isNormal (const typename t::fpt &format, const unpackedFloat<t> &uf) {
27
43
  PRECONDITION(uf.valid(format));
28
29
43
  return !uf.getNaN() && !uf.getInf() && !uf.getZero() && uf.inNormalRange(format, typename t::prop(true));
30
 }
31
32
33
template <class t>
34
44
  typename t::prop isSubnormal (const typename t::fpt &format, const unpackedFloat<t> &uf) {
35
44
  PRECONDITION(uf.valid(format));
36
37
44
  return !uf.getNaN() && !uf.getInf() && !uf.getZero() && uf.inSubnormalRange(format, typename t::prop(true));
38
 }
39
40
41
template <class t>
42
168
  typename t::prop isZero (const typename t::fpt &format, const unpackedFloat<t> &uf) {
43
168
  PRECONDITION(uf.valid(format));
44
45
168
  return uf.getZero();
46
 }
47
48
49
template <class t>
50
54
  typename t::prop isInfinite (const typename t::fpt &format, const unpackedFloat<t> &uf) {
51
54
  PRECONDITION(uf.valid(format));
52
53
54
  return uf.getInf();
54
 }
55
56
57
template <class t>
58
63
  typename t::prop isNaN (const typename t::fpt &format, const unpackedFloat<t> &uf) {
59
63
  PRECONDITION(uf.valid(format));
60
61
63
  return uf.getNaN();
62
 }
63
64
65
// Note these are the SMT-LIB semantics, NaN is neither positive or negative
66
67
template <class t>
68
16
  typename t::prop isPositive (const typename t::fpt &format, const unpackedFloat<t> &uf) {
69
16
  PRECONDITION(uf.valid(format));
70
71
16
  return !uf.getNaN() && !uf.getSign();
72
 }
73
74
template <class t>
75
35
  typename t::prop isNegative (const typename t::fpt &format, const unpackedFloat<t> &uf) {
76
35
  PRECONDITION(uf.valid(format));
77
78
35
  return !uf.getNaN() && uf.getSign();
79
 }
80
81
82
// C semantics
83
84
 template <class t>
85
  typename t::prop isFinite (const typename t::fpt &format, const unpackedFloat<t> &uf) {
86
  PRECONDITION(uf.valid(format));
87
88
  return !uf.getNaN() && !uf.getInf();
89
 }
90
91
92
}
93
94
#endif
95