GCC Code Coverage Report
Directory: . Exec Total Coverage
File: build-coverage/deps/include/symfpu/core/classify.h Lines: 21 21 100.0 %
Date: 2021-09-29 Branches: 43 64 67.2 %

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
42
  typename t::prop isNormal (const typename t::fpt &format, const unpackedFloat<t> &uf) {
27
42
  PRECONDITION(uf.valid(format));
28
29
42
  return !uf.getNaN() && !uf.getInf() && !uf.getZero() && uf.inNormalRange(format, typename t::prop(true));
30
 }
31
32
33
template <class t>
34
42
  typename t::prop isSubnormal (const typename t::fpt &format, const unpackedFloat<t> &uf) {
35
42
  PRECONDITION(uf.valid(format));
36
37
42
  return !uf.getNaN() && !uf.getInf() && !uf.getZero() && uf.inSubnormalRange(format, typename t::prop(true));
38
 }
39
40
41
template <class t>
42
199
  typename t::prop isZero (const typename t::fpt &format, const unpackedFloat<t> &uf) {
43
199
  PRECONDITION(uf.valid(format));
44
45
199
  return uf.getZero();
46
 }
47
48
49
template <class t>
50
127
  typename t::prop isInfinite (const typename t::fpt &format, const unpackedFloat<t> &uf) {
51
127
  PRECONDITION(uf.valid(format));
52
53
127
  return uf.getInf();
54
 }
55
56
57
template <class t>
58
172
  typename t::prop isNaN (const typename t::fpt &format, const unpackedFloat<t> &uf) {
59
172
  PRECONDITION(uf.valid(format));
60
61
172
  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
11
  typename t::prop isPositive (const typename t::fpt &format, const unpackedFloat<t> &uf) {
69
11
  PRECONDITION(uf.valid(format));
70
71
11
  return !uf.getNaN() && !uf.getSign();
72
 }
73
74
template <class t>
75
33
  typename t::prop isNegative (const typename t::fpt &format, const unpackedFloat<t> &uf) {
76
33
  PRECONDITION(uf.valid(format));
77
78
33
  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