21
21
// / TODO: factorize with float_bv.cpp float_utils.h
22
22
// / \param src: a floating point expression
23
23
// / \param spec: specification for floating points
24
- // / \return A 32 bit integer representing the exponent. Note that 32 bits are
25
- // / sufficient for the exponent even in octuple precision.
24
+ // / \return A new 32 bit integer expression representing the exponent.
25
+ // / Note that 32 bits are sufficient for the exponent even
26
+ // / in octuple precision.
26
27
exprt get_exponent (
27
28
const exprt &src, const ieee_float_spect &spec)
28
29
{
29
30
exprt exp_bits=extractbits_exprt (
30
31
src, spec.f +spec.e -1 , spec.f , unsignedbv_typet (spec.e ));
31
32
32
- // Exponent is in biased from (numbers form -128 to 127 are encoded with
33
+ // Exponent is in biased from (numbers from -128 to 127 are encoded with
33
34
// integer from 0 to 255) we have to remove the bias.
34
35
return minus_exprt (
35
36
typecast_exprt (exp_bits, signedbv_typet (32 )),
@@ -45,7 +46,10 @@ exprt get_magnitude(const exprt &src, const ieee_float_spect &spec)
45
46
return extractbits_exprt (src, spec.f -1 , 0 , unsignedbv_typet (spec.f ));
46
47
}
47
48
48
- // / Gets the significand as a java integer, looking for the hidden bit
49
+ // / Gets the significand as a java integer, looking for the hidden bit.
50
+ // / Since the most significant bit is 1 for normalized number, it is not part
51
+ // / of the encoding of the significand and is 0 only if all the bits of the
52
+ // / exponent are 0, that is why it is called the hidden bit.
49
53
// / \param src: a floating point expression
50
54
// / \param spec: specification for floating points
51
55
// / \param type: type of the output, should be unsigned with width greater than
@@ -65,6 +69,7 @@ exprt get_significand(
65
69
return if_exprt (all_zeros, magnitude, with_hidden_bit);
66
70
}
67
71
72
+ // / Create an expression to represent a float or double value.
68
73
// / \param f: a floating point value in double precision
69
74
// / \return an expression representing this floating point
70
75
exprt constant_float (const double f, const ieee_float_spect &float_spec)
@@ -109,7 +114,7 @@ exprt floatbv_mult(const exprt &f, const exprt &g)
109
114
// / other values that are in floating point representation.
110
115
// / \param i: an expression representing an integer
111
116
// / \param spec: specification for floating point numbers
112
- // / \return An expression representing representing the value of the input
117
+ // / \return An expression representing the value of the input
113
118
// / integer as a float.
114
119
exprt floatbv_of_int_expr (const exprt &i, const ieee_float_spect &spec)
115
120
{
@@ -119,14 +124,14 @@ exprt floatbv_of_int_expr(const exprt &i, const ieee_float_spect &spec)
119
124
120
125
// / Estimate the decimal exponent that should be used to represent a given
121
126
// / floating point value in decimal.
122
- // / We are looking for d such that n * 10^d = m * 10 ^e, so:
127
+ // / We are looking for d such that n * 10^d = m * 2 ^e, so:
123
128
// / d = log_10(m) + log_10(2) * e - log_10(n)
124
129
// / m -- the magnitude -- should be between 1 and 2 so log_10(m)
125
130
// / in [0,log_10(2)].
126
131
// / n -- the magnitude in base 10 -- should be between 1 and 10 so
127
132
// / log_10(n) in [0, 1].
128
133
// / So the estimate is given by:
129
- // / d ~=~ floor( log_10(2) * e)
134
+ // / d ~=~ floor(log_10(2) * e)
130
135
// / \param f: a floating point expression
131
136
// / \param spec: specification for floating point
132
137
exprt estimate_decimal_exponent (const exprt &f, const ieee_float_spect &spec)
@@ -136,13 +141,13 @@ exprt estimate_decimal_exponent(const exprt &f, const ieee_float_spect &spec)
136
141
exprt float_bin_exp=floatbv_of_int_expr (bin_exp, spec);
137
142
exprt dec_exp=floatbv_mult (float_bin_exp, log_10_of_2);
138
143
binary_relation_exprt negative_exp (dec_exp, ID_lt, constant_float (0.0 , spec));
139
- // Rounding to zero is not correct for negative number , so we remove 1.
144
+ // Rounding to zero is not correct for negative numbers , so we substract 1.
140
145
minus_exprt dec_minus_one (dec_exp, constant_float (1.0 , spec));
141
146
if_exprt adjust_for_neg (negative_exp, dec_minus_one, dec_exp);
142
147
return round_expr_to_zero (adjust_for_neg);
143
148
}
144
149
145
- // / add axioms corresponding to the String.valueOf(F) java function
150
+ // / Add axioms corresponding to the String.valueOf(F) java function
146
151
// / \param f: function application with one float argument
147
152
// / \return a new string expression
148
153
string_exprt string_constraint_generatort::add_axioms_from_float (
@@ -152,7 +157,7 @@ string_exprt string_constraint_generatort::add_axioms_from_float(
152
157
return add_axioms_from_float (args (f, 1 )[0 ], ref_type);
153
158
}
154
159
155
- // / add axioms corresponding to the String.valueOf(D) java function
160
+ // / Add axioms corresponding to the String.valueOf(D) java function
156
161
// / \param f: function application with one double argument
157
162
// / \return a new string expression
158
163
string_exprt string_constraint_generatort::add_axioms_from_double (
@@ -162,7 +167,7 @@ string_exprt string_constraint_generatort::add_axioms_from_double(
162
167
return add_axioms_from_float (args (f, 1 )[0 ], ref_type);
163
168
}
164
169
165
- // / add axioms corresponding to the integer part of m, in decimal form with no
170
+ // / Add axioms corresponding to the integer part of m, in decimal form with no
166
171
// / leading zeroes, followed by '.' ('\u002E'), followed by one or more decimal
167
172
// / digits representing the fractional part of m.
168
173
// /
0 commit comments