82 return std::string(
m_rep->
to_string(numrep, (w_prefix ? 1 : 0), SC_E));
100 return std::string(
m_rep->
to_string(numrep, (w_prefix ? 1 : 0), fmt));
144 os <<
"sc_fxval" << ::std::endl;
145 os <<
"(" << ::std::endl;
155 os <<
")" << ::std::endl;
171 SC_ASSERT_(observer_ != 0,
"unlock observer failed");
185 if (
id.negative() != 0) {
201 double frac_part = std::modf(
static_cast<double>(
id), &int_part);
209 if (int_part != 0.0) {
210 int_digits = (int)std::ceil(std::log10(int_part + 1.0));
212 int len = s.length();
213 s.append(int_digits);
215 bool zero_digits = (frac_part == 0.0 && fmt !=
SC_F);
217 for (i = int_digits +
len - 1; i >=
len; i--) {
218 unsigned int remainder = (
unsigned int)std::fmod(int_part, 10.0);
219 s[i] =
static_cast<char>(
'0' +
remainder);
232 s.discard(int_zeros);
245 if (frac_part != 0.0) {
248 bool zero_digits = (int_digits == 0 && fmt !=
SC_F);
250 frac_zeros = (int)std::floor(-std::log10(frac_part + DBL_EPSILON));
252 frac_part *= std::pow(10.0, frac_zeros);
254 frac_digits = frac_zeros;
256 for (i = 0; i < frac_zeros; i++)
261 while (frac_part != 0.0) {
263 int n =
static_cast<int>(frac_part);
273 s +=
static_cast<char>(
'0' + n);
282 if (frac_digits == 0)
284 else if (int_digits == 0)
297 bool numrep_is_sm = (numrep == SC_BIN_SM ||
298 numrep == SC_OCT_SM ||
332 msb = params->
iwl() - 1;
333 lsb = params->
iwl() - params->
wl();
336 (numrep == SC_BIN_US ||
337 numrep == SC_OCT_US ||
338 numrep == SC_HEX_US) &&
355 while (
a.get_bit(msb) ==
a.get_bit(msb - 1))
358 if (numrep == SC_BIN_US ||
359 numrep == SC_OCT_US ||
360 numrep == SC_HEX_US) {
365 while (!
a.get_bit(lsb))
388 "unexpected sc_numrep");
392 msb = (int)std::ceil(
double(msb + 1) / step) * step - 1;
394 lsb = (int)std::floor(
double(lsb) / step) * step;
399 int sign = (id2.
negative() != 0) ? (1 << step) - 1 : 0;
400 for (
int i = (msb + 1) / step; i < 0; i++) {
402 s +=
static_cast<char>(sign +
'0');
404 s +=
static_cast<char>(sign +
'a' - 10);
412 for (
int j = step - 1; j >= 0; --j) {
413 value +=
static_cast<int>(
a.get_bit(i)) << j;
417 s +=
static_cast<char>(value +
'0');
419 s +=
static_cast<char>(value +
'a' - 10);
424 if (lsb > 0 && fmt == SC_F) {
425 for (
int i = lsb / step; i > 0; i--)
429 if (s[s.length() - 1] ==
'.')
439 if (numrep == SC_CSD)
455 }
else if (
id.negative() && !
id.is_zero() &&
456 (numrep == SC_BIN_US ||
457 numrep == SC_OCT_US ||
458 numrep == SC_HEX_US)) {
460 }
else if (numrep == SC_DEC) {
553 os <<
"sc_fxval_fast" << ::std::endl;
554 os <<
"(" << ::std::endl;
555 os <<
"val = " <<
m_val << ::std::endl;
563 os <<
")" << ::std::endl;
576 unsigned int m0 =
id.mantissa0();
577 unsigned int m1 =
id.mantissa1();
582 if (
id.negative() != 0) {
585 unsigned int tmp = m1;
592 int j = i -
id.exponent();
594 return ((m0 & 1U << 31) != 0);
596 return ((m0 & 1U << j) != 0);
597 else if ((j += 32) >= 0)
598 return ((m1 & 1U << j) != 0);
617 SC_ASSERT_(observer_ != 0,
"unlock observer failed");
621#define SCFX_FAIL_IF_(cnd) \
624 return static_cast<double>(scfx_ieee_double::nan()); \
695 s = (
const char*) s2 + 4;
707 bool based_point =
false;
734 for (
const char *e = end + 2; *e; e++)
736 exponent = std::atoi(end + 1);
742 double integer = 0.0;
743 if (int_digits != 0) {
744 bool first_digit =
true;
746 for (; s < end; s++) {
757 if (integer >= (base >> 1))
773 double fraction = 0.0;
774 if (frac_digits != 0) {
777 bool first_digit = (int_digits == 0);
779 for (; s < end; s++) {
789 if (fraction >= (base >> 1))
805 (exponent != 0) ? std::pow((
double) base, (double) exponent) : 1;
807 return (sign * (integer + fraction) * exp);
void print(::std::ostream &=::std::cout) const
sc_fxval_fast_observer * m_observer
sc_fxval_fast_observer * lock_observer() const
const std::string to_string() const
void dump(::std::ostream &=::std::cout) const
const std::string to_oct() const
const std::string to_hex() const
void scan(::std::istream &=::std::cin)
static double from_string(const char *)
void unlock_observer(sc_fxval_fast_observer *) const
const std::string to_bin() const
const std::string to_dec() const
const std::string to_string() const
const std::string to_bin() const
const std::string to_dec() const
void scan(::std::istream &=::std::cin)
void unlock_observer(sc_fxval_observer *) const
const std::string to_hex() const
const std::string to_oct() const
sc_fxval_observer * lock_observer() const
void print(::std::ostream &=::std::cout) const
void dump(::std::ostream &=::std::cout) const
sc_fxval_observer * m_observer
static const scfx_ieee_double nan()
static const scfx_ieee_double inf(int)
unsigned int negative() const
void dump(::std::ostream &) const
void print(::std::ostream &) const
const char * to_string(sc_numrep, int, sc_fmt, const scfx_params *=0) const
const char SC_ID_ASSERTION_FAILED_[]
static void print_other(scfx_string &s, const scfx_ieee_double &id, sc_numrep numrep, int w_prefix, sc_fmt fmt, const scfx_params *params)
bool scfx_is_inf(const char *s)
bool scfx_is_digit(char c, sc_numrep numrep)
void scfx_print_inf(scfx_string &s, bool negative)
int scfx_parse_sign(const char *&s, bool &sign_char)
bool scfx_is_nan(const char *s)
void scfx_print_prefix(scfx_string &s, sc_numrep numrep)
sc_numrep scfx_parse_prefix(const char *&s)
void scfx_csd2tc(scfx_string &csd)
void scfx_print_exp(scfx_string &s, int exp)
int scfx_to_digit(char c, sc_numrep numrep)
void scfx_print_nan(scfx_string &s)
const std::string to_string(sc_enc enc)
static void print_dec(scfx_string &s, scfx_ieee_double id, int w_prefix, sc_fmt fmt)
void scfx_tc2csd(scfx_string &s, int w_prefix)
bool scfx_exp_start(const char *s)
#define SC_ASSERT_(cnd, msg)
#define SCFX_FAIL_IF_(cnd)
#define SC_REPORT_FATAL(msg_type, msg)