GCC Code Coverage Report
Directory: . Exec Total Coverage
File: build-coverage/deps/include/symfpu/core/classify.h Lines: 21 21 100.0 %
Date: 2021-08-17 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
40
  typename t::prop isNormal (const typename t::fpt &format, const unpackedFloat<t> &uf) {
27
40
  PRECONDITION(uf.valid(format));
28
29
40
  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
157
  typename t::prop isZero (const typename t::fpt &format, const unpackedFloat<t> &uf) {
43
157
  PRECONDITION(uf.valid(format));
44
45
157
  return uf.getZero();
46
 }
47
48
49
template <class t>
50
48
  typename t::prop isInfinite (const typename t::fpt &format, const unpackedFloat<t> &uf) {
51
48
  PRECONDITION(uf.valid(format));
52
53
48
  return uf.getInf();
54
 }
55
56
57
template <class t>
58
65
  typename t::prop isNaN (const typename t::fpt &format, const unpackedFloat<t> &uf) {
59
65
  PRECONDITION(uf.valid(format));
60
61
65
  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
14
  typename t::prop isPositive (const typename t::fpt &format, const unpackedFloat<t> &uf) {
69
14
  PRECONDITION(uf.valid(format));
70
71
14
  return !uf.getNaN() && !uf.getSign();
72
 }
73
74
template <class t>
75
34
  typename t::prop isNegative (const typename t::fpt &format, const unpackedFloat<t> &uf) {
76
34
  PRECONDITION(uf.valid(format));
77
78
34
  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