Go to the documentation of this file.
30 result.
set(ID_x86_extended,
true);
51 "mantissa bits must be less than "
52 "originating type width");
73 switch(format_spec.
style)
98 if(adjusted_exponent>=format_spec.
precision ||
111 std::size_t trunc_pos=result.find_last_not_of(
'0');
112 if(trunc_pos!=std::string::npos)
113 result.resize(trunc_pos+1);
116 if(!result.empty() && result.back()==
'.')
117 result.resize(result.size()-1);
123 while(result.size()<format_spec.
min_width)
134 while(tmp!=0) { ++result; tmp/=10; }
161 for(std::size_t i=0; i<precision; i++)
179 for(std::size_t i=0; i<precision; i++)
189 _fraction*=
power(5, position);
192 if(position>precision)
206 while(
mp_integer(tmp.size())<=position) tmp=
"0"+tmp;
208 const std::size_t
dot =
209 tmp.size() - numeric_cast_v<std::size_t>(position);
210 result+=std::string(tmp, 0,
dot)+
'.';
211 result+=std::string(tmp,
dot, std::string::npos);
255 for(std::size_t i=0; i<precision; i++)
282 else if(remainder>p/2)
298 while(decimals.size()<precision+1)
301 result+=decimals.substr(1, precision);
307 std::string exponent_str=
310 if(!exponent_str.empty() && exponent_str[0]!=
'-')
313 result+=exponent_str;
418 _fraction=_exponent=0;
429 while((_fraction%2)==0)
442 _fraction=_exponent=0;
455 _fraction*=
power(2, _exponent);
461 _fraction*=
power(5, -_exponent);
465 while((_fraction%10)==0)
552 std::size_t lowPower2=
fraction.floorPow2();
557 exponent_offset-=(
spec.
f-lowPower2);
561 "normalisation result must be >= lower bound");
564 "normalisation result must be < upper bound");
566 else if(lowPower2>
spec.
f)
568 exponent_offset+=(lowPower2-
spec.
f);
572 "normalisation result must be >= lower bound");
575 "normalisation result must be < upper bound");
624 else if(biased_exponent<=0)
628 exponent_offset=new_exponent-
exponent;
633 if(exponent_offset>0)
644 else if(exponent_offset<0)
655 const mp_integer remainder = dividend % divisor;
665 if(remainder < divisor_middle)
669 else if(remainder > divisor_middle)
675 if((dividend % 2) != 0)
877 "prior block equalises the exponents by setting both to the "
878 "minimum of their previous values while adjusting the mantissa");
912 return (*
this)+=_other;
1023 return *
this==other;
1030 return *
this==other;
1035 return !(*
this==other);
1045 return *
this!=other;
1064 build(_fraction, _exponent);
1084 result/=
power(2, -new_exponent);
1086 result*=
power(2, new_exponent);
1101 std::numeric_limits<double>::is_iec559,
1102 "this requires the double layout is according to the ieee754 "
1105 sizeof(
double) ==
sizeof(std::uint64_t),
"ensure double has 64 bit width");
1125 std::numeric_limits<float>::is_iec559,
1126 "this requires the float layout is according to the ieee754 "
1129 sizeof(
float) ==
sizeof(std::uint32_t),
"ensure float has 32 bit width");
1193 union {
double f; uint64_t i; } a;
1198 return -std::numeric_limits<double>::infinity();
1200 return std::numeric_limits<double>::infinity();
1206 return -std::numeric_limits<double>::quiet_NaN();
1208 return std::numeric_limits<double>::quiet_NaN();
1213 CHECK_RETURN(i <= std::numeric_limits<std::uint64_t>::max());
1225 std::numeric_limits<float>::is_iec559,
1226 "this requires the float layout is according to the IEC 559/IEEE 754 "
1229 sizeof(
float) ==
sizeof(uint32_t),
"a 32 bit float type is required");
1231 union {
float f; uint32_t i; } a;
1236 return -std::numeric_limits<float>::infinity();
1238 return std::numeric_limits<float>::infinity();
1244 return -std::numeric_limits<float>::quiet_NaN();
1246 return std::numeric_limits<float>::quiet_NaN();
1249 a.i = numeric_cast_v<uint32_t>(
pack());
#define UNREACHABLE
This should be used to mark dead code.
void set_f(std::size_t b)
bool operator==(const ieee_floatt &other) const
mp_integer max_fraction() const
void set_sign(bool _sign)
void print(std::ostream &out) const
#define CHECK_RETURN(CONDITION)
void extract_base2(mp_integer &_exponent, mp_integer &_fraction) const
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
std::size_t get_f() const
std::string to_ansi_c_string() const
void dot(const goto_modelt &src, std::ostream &out)
Fixed-width bit-vector with IEEE floating-point interpretation.
bool operator<(const ieee_floatt &other) const
void unpack(const mp_integer &i)
float to_float() const
Note that calling from_float -> to_float can return different bit patterns for NaN.
void change_spec(const ieee_float_spect &dest_spec)
mp_integer to_integer() const
bool operator!=(const ieee_floatt &other) const
void from_type(const floatbv_typet &type)
void from_float(const float f)
ieee_floatt & operator+=(const ieee_floatt &other)
double to_double() const
Note that calling from_double -> to_double can return different bit patterns for NaN.
typet & type()
Return the type of the expression.
bool operator<=(const ieee_floatt &other) const
static ieee_float_spect double_precision()
std::size_t width() const
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
void set(const irep_idt &name, const irep_idt &value)
class floatbv_typet to_type() const
#define PRECONDITION(CONDITION)
bool ieee_equal(const ieee_floatt &other) const
void make_plus_infinity()
bool operator>(const ieee_floatt &other) const
void from_base10(const mp_integer &exp, const mp_integer &frac)
compute f * (10^e)
void divide_and_round(mp_integer ÷nd, const mp_integer &divisor)
void from_integer(const mp_integer &i)
void set_width(std::size_t width)
rounding_modet rounding_mode
std::string to_string_decimal(std::size_t precision) const
std::size_t get_width() const
static constant_exprt rounding_mode_expr(rounding_modet)
bool ieee_not_equal(const ieee_floatt &other) const
std::string to_string_scientific(std::size_t precision) const
format as [-]d.ddde+-d Note that printf always produces at least two digits for the exponent.
mp_integer max_exponent() const
void make_minus_infinity()
constant_exprt to_expr() const
constant_exprt floatbv_rounding_mode(unsigned rm)
returns the a rounding mode expression for a given IEEE rounding mode, encoded using the recommendati...
std::string format(const format_spect &format_spec) const
static mp_integer base10_digits(const mp_integer &src)
A constant literal expression.
ieee_floatt & operator-=(const ieee_floatt &other)
bool operator>=(const ieee_floatt &other) const
const irep_idt & get_value() const
void next_representable(bool greater)
Sets *this to the next representable number closer to plus infinity (greater = true) or minus infinit...
bool get_bool(const irep_idt &name) const
ieee_floatt & operator/=(const ieee_floatt &other)
ieee_floatt & operator*=(const ieee_floatt &other)
void extract_base10(mp_integer &_exponent, mp_integer &_fraction) const
void from_expr(const constant_exprt &expr)
void build(const mp_integer &exp, const mp_integer &frac)
const std::string integer2string(const mp_integer &n, unsigned base)
void from_double(const double d)