32 result.
set(ID_x86_extended,
true);
53 "mantissa bits must be less than " 54 "originating type width");
70 switch(format_spec.
style)
95 if(adjusted_exponent>=format_spec.
precision ||
108 std::size_t trunc_pos=result.find_last_not_of(
'0');
109 if(trunc_pos!=std::string::npos)
110 result.resize(trunc_pos+1);
113 if(!result.empty() && result.back()==
'.')
114 result.resize(result.size()-1);
120 while(result.size()<format_spec.
min_width)
131 while(tmp!=0) { ++result; tmp/=10; }
158 for(std::size_t i=0; i<precision; i++)
176 for(std::size_t i=0; i<precision; i++)
186 _fraction*=
power(5, position);
189 if(position>precision)
203 while(
mp_integer(tmp.size())<=position) tmp=
"0"+tmp;
205 const std::size_t
dot =
206 tmp.size() - numeric_cast_v<std::size_t>(position);
207 result+=std::string(tmp, 0,
dot)+
'.';
208 result+=std::string(tmp,
dot, std::string::npos);
252 for(std::size_t i=0; i<precision; i++)
279 else if(remainder>p/2)
295 while(decimals.size()<precision+1)
298 result+=decimals.substr(1, precision);
304 std::string exponent_str=
307 if(!exponent_str.empty() && exponent_str[0]!=
'-')
310 result+=exponent_str;
415 _fraction=_exponent=0;
426 while((_fraction%2)==0)
439 _fraction=_exponent=0;
452 _fraction*=
power(2, _exponent);
458 _fraction*=
power(5, -_exponent);
462 while((_fraction%10)==0)
549 std::size_t lowPower2=
fraction.floorPow2();
554 exponent_offset-=(
spec.
f-lowPower2);
558 "normalisation result must be >= lower bound");
561 "normalisation result must be < upper bound");
563 else if(lowPower2>
spec.
f)
565 exponent_offset+=(lowPower2-
spec.
f);
569 "normalisation result must be >= lower bound");
572 "normalisation result must be < upper bound");
621 else if(biased_exponent<=0)
625 exponent_offset=new_exponent-
exponent;
630 if(exponent_offset>0)
641 else if(exponent_offset<0)
652 const mp_integer remainder = dividend % divisor;
662 if(remainder < divisor_middle)
666 else if(remainder > divisor_middle)
672 if((dividend % 2) != 0)
873 "prior block equalises the exponents by setting both to the " 874 "minimum of their previous values while adjusting the mantissa");
908 return (*
this)+=_other;
1019 return *
this==other;
1026 return *
this==other;
1031 return !(*
this==other);
1041 return *
this!=other;
1060 build(_fraction, _exponent);
1080 result/=
power(2, -new_exponent);
1082 result*=
power(2, new_exponent);
1097 std::numeric_limits<double>::is_iec559,
1098 "this requires the double layout is according to the ieee754 " 1101 sizeof(
double) ==
sizeof(std::uint64_t),
"ensure double has 64 bit width");
1121 std::numeric_limits<float>::is_iec559,
1122 "this requires the float layout is according to the ieee754 " 1125 sizeof(
float) ==
sizeof(std::uint32_t),
"ensure float has 32 bit width");
1189 union {
double f; uint64_t i; } a;
1194 return -std::numeric_limits<double>::infinity();
1196 return std::numeric_limits<double>::infinity();
1202 return -std::numeric_limits<double>::quiet_NaN();
1204 return std::numeric_limits<double>::quiet_NaN();
1209 CHECK_RETURN(i <= std::numeric_limits<std::uint64_t>::max());
1221 std::numeric_limits<float>::is_iec559,
1222 "this requires the float layout is according to the IEC 559/IEEE 754 " 1225 sizeof(
float) ==
sizeof(uint32_t),
"a 32 bit float type is required");
1227 union {
float f; uint32_t i; } a;
1232 return -std::numeric_limits<float>::infinity();
1234 return std::numeric_limits<float>::infinity();
1240 return -std::numeric_limits<float>::quiet_NaN();
1242 return std::numeric_limits<float>::quiet_NaN();
1247 CHECK_RETURN(i <= std::numeric_limits<std::uint32_t>::max());
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.
ieee_floatt & operator-=(const ieee_floatt &other)
bool operator>=(const ieee_floatt &other) const
bool operator!=(const ieee_floatt &other) const
const std::string integer2string(const mp_integer &n, unsigned base)
constant_exprt to_expr() const
Fixed-width bit-vector with IEEE floating-point interpretation.
ieee_floatt & operator+=(const ieee_floatt &other)
void from_expr(const constant_exprt &expr)
void build(const mp_integer &exp, const mp_integer &frac)
bool operator==(const ieee_floatt &other) const
const irep_idt & get_value() const
void from_type(const floatbv_typet &type)
void next_representable(bool greater)
Sets *this to the next representable number closer to plus infinity (greater = true) or minus infinit...
void set_sign(bool _sign)
void print(std::ostream &out) const
typet & type()
Return the type of the expression.
mp_integer max_exponent() const
A constant literal expression.
#define CHECK_RETURN(CONDITION)
bool get_bool(const irep_namet &name) const
mp_integer max_fraction() const
static ieee_float_spect double_precision()
class floatbv_typet to_type() const
void change_spec(const ieee_float_spect &dest_spec)
void extract_base2(mp_integer &_exponent, mp_integer &_fraction) const
void dot(const goto_modelt &src, std::ostream &out)
mp_integer to_integer() const
bool ieee_equal(const ieee_floatt &other) const
void unpack(const mp_integer &i)
API to expression classes.
double to_double() const
Note that calling from_double -> to_double can return different bit patterns for NaN.
void from_base10(const mp_integer &exp, const mp_integer &frac)
compute f * (10^e)
bool operator<=(const ieee_floatt &other) const
#define PRECONDITION(CONDITION)
void from_float(const float f)
std::size_t get_width() const
std::string format(const format_spect &format_spec) const
void make_minus_infinity()
std::size_t get_f() const
static mp_integer base10_digits(const mp_integer &src)
void make_plus_infinity()
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
void from_double(const double d)
bool operator>(const ieee_floatt &other) const
#define UNREACHABLE
This should be used to mark dead code.
ieee_floatt & operator/=(const ieee_floatt &other)
std::string to_string_decimal(std::size_t precision) const
void divide_and_round(mp_integer ÷nd, const mp_integer &divisor)
void from_integer(const mp_integer &i)
void extract_base10(mp_integer &_exponent, mp_integer &_fraction) const
ieee_floatt & operator *=(const ieee_floatt &other)
bool ieee_not_equal(const ieee_floatt &other) const
void set_f(std::size_t b)
rounding_modet rounding_mode
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,...
std::string to_ansi_c_string() const
float to_float() const
Note that calling from_float -> to_float can return different bit patterns for NaN.
void set(const irep_namet &name, const irep_idt &value)
bool operator<(const ieee_floatt &other) const
void set_width(std::size_t width)