Commit f34d0de8 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Modernize code

parent 227c7521
......@@ -75,7 +75,7 @@ KCalculator::KCalculator(QWidget *parent) :
core() {
// central widget to contain all the elements
QWidget *const central = new QWidget(this);
auto const central = new QWidget(this);
central->setLayoutDirection(Qt::LeftToRight);
setCentralWidget(central);
KAcceleratorManager::setNoAccel(central);
......@@ -182,7 +182,7 @@ void KCalculator::setupMainActions() {
KStandardAction::paste(this, SLOT(slotPaste()), actionCollection());
// mode menu
QActionGroup *modeGroup = new QActionGroup(this);
auto modeGroup = new QActionGroup(this);
action_mode_simple_ = actionCollection()->add<KToggleAction>(QStringLiteral("mode_simple"));
action_mode_simple_->setActionGroup(modeGroup);
......@@ -225,7 +225,7 @@ void KCalculator::setupMainActions() {
//------------------------------------------------------------------------------
KCalcConstMenu *KCalculator::createConstantsMenu() {
KCalcConstMenu *const menu = new KCalcConstMenu(i18n("&Constants"), this);
auto const menu = new KCalcConstMenu(i18n("&Constants"), this);
connect(menu, &KCalcConstMenu::triggeredConstant, this, &KCalculator::slotConstantToDisplay);
return menu;
}
......@@ -687,7 +687,7 @@ void KCalculator::updateGeometry() {
// left pad
foreach(QObject *obj, leftPad->children()) {
if (KCalcButton *const button = qobject_cast<KCalcButton *>(obj)) {
if (auto const button = qobject_cast<KCalcButton *>(obj)) {
button->setFixedWidth(em.width() * 4 + margin * 2);
button->installEventFilter(this);
}
......@@ -695,7 +695,7 @@ void KCalculator::updateGeometry() {
// right pad
foreach(QObject *obj, rightPad->children()) {
KCalcButton *const button = qobject_cast<KCalcButton *>(obj);
auto const button = qobject_cast<KCalcButton *>(obj);
// let Shift expand freely
if (button && button != pbShift) {
button->setFixedWidth(em.width() * 3 + margin * 2);
......@@ -705,7 +705,7 @@ void KCalculator::updateGeometry() {
// numeric pad
foreach(QObject *obj, numericPad->children()) {
if (KCalcButton *const button = qobject_cast<KCalcButton *>(obj)) {
if (auto const button = qobject_cast<KCalcButton *>(obj)) {
// let pb0 expand freely
if (button != pb0) {
button->setFixedWidth(em.width() * 3 + margin * 2);
......@@ -1585,7 +1585,7 @@ void KCalculator::slotStatClearDataclicked() {
//------------------------------------------------------------------------------
void KCalculator::slotConstclicked(int button) {
if(KCalcConstButton *btn = qobject_cast<KCalcConstButton*>(const_buttons_[button])) {
if(auto btn = qobject_cast<KCalcConstButton*>(const_buttons_[button])) {
if (!shift_mode_) {
// set the display to the configured value of constant button
// internally, we deal with C locale style numbers, we need to convert
......@@ -1627,19 +1627,19 @@ void KCalculator::showSettings() {
}
// Create a new dialog with the same name as the above checking code.
KConfigDialog *const dialog = new KConfigDialog(this, QStringLiteral("settings"), KCalcSettings::self());
auto const dialog = new KConfigDialog(this, QStringLiteral("settings"), KCalcSettings::self());
// general settings
General *const general = new General(nullptr);
auto const general = new General(nullptr);
general->kcfg_Precision->setMaximum(maxprecision);
dialog->addPage(general, i18n("General"), QStringLiteral("accessories-calculator"), i18n("General Settings"));
// font settings
Fonts *const fonts = new Fonts(nullptr);
auto const fonts = new Fonts(nullptr);
dialog->addPage(fonts, i18n("Font"), QStringLiteral("preferences-desktop-font"), i18n("Select Display Font"));
// color settings
Colors *const color = new Colors(nullptr);
auto const color = new Colors(nullptr);
dialog->addPage(color, i18n("Colors"), QStringLiteral("preferences-desktop-color"), i18n("Button & Display Colors"));
// constant settings
......@@ -2064,7 +2064,7 @@ void KCalculator::slotBitsetshow(bool toggled) {
void KCalculator::changeButtonNames() {
foreach(QAbstractButton *btn, const_buttons_) {
if (KCalcConstButton *const constbtn = qobject_cast<KCalcConstButton*>(btn)) {
if (auto const constbtn = qobject_cast<KCalcConstButton*>(btn)) {
constbtn->setLabelAndTooltip();
}
}
......@@ -2233,19 +2233,19 @@ void KCalculator::setColors() {
void KCalculator::setFonts() {
foreach(QObject *obj, leftPad->children()) {
if (KCalcButton *const button = qobject_cast<KCalcButton*>(obj)) {
if (auto const button = qobject_cast<KCalcButton*>(obj)) {
button->setFont(KCalcSettings::buttonFont());
}
}
foreach(QObject *obj, numericPad->children()) {
if (KCalcButton *const button = qobject_cast<KCalcButton*>(obj)) {
if (auto const button = qobject_cast<KCalcButton*>(obj)) {
button->setFont(KCalcSettings::buttonFont());
}
}
foreach(QObject *obj, rightPad->children()) {
if (KCalcButton *const button = qobject_cast<KCalcButton*>(obj)) {
if (auto const button = qobject_cast<KCalcButton*>(obj)) {
button->setFont(KCalcSettings::buttonFont());
}
}
......@@ -2311,7 +2311,7 @@ bool KCalculator::eventFilter(QObject *o, QEvent *e) {
switch (e->type()) {
case QEvent::DragEnter: {
QDragEnterEvent *const ev = reinterpret_cast<QDragEnterEvent *>(e);
auto const ev = reinterpret_cast<QDragEnterEvent *>(e);
ev->setAccepted(KColorMimeData::canDecode(ev->mimeData()));
return true;
}
......@@ -2319,12 +2319,12 @@ bool KCalculator::eventFilter(QObject *o, QEvent *e) {
return true;
}
case QEvent::Drop: {
KCalcButton *const calcButton = qobject_cast<KCalcButton *>(o);
auto const calcButton = qobject_cast<KCalcButton *>(o);
if (!calcButton) {
return false;
}
QDropEvent *const ev = reinterpret_cast<QDropEvent *>(e);
auto const ev = reinterpret_cast<QDropEvent *>(e);
QColor c = KColorMimeData::fromMimeData(ev->mimeData());
if (c.isValid()) {
......@@ -2443,7 +2443,7 @@ int main(int argc, char *argv[]) {
KNumber::setGroupSeparator(QLocale().groupSeparator());
KNumber::setDecimalSeparator(QString(QLocale().decimalPoint()));
KCalculator *calc = new KCalculator(nullptr);
auto calc = new KCalculator(nullptr);
calc->show();
return app.exec();
......
......@@ -82,7 +82,7 @@ KCalcBitset::KCalcBitset(QWidget *parent) : QFrame(parent), bit_button_group_(ne
}
// main layout
QGridLayout *layout = new QGridLayout(this);
auto layout = new QGridLayout(this);
layout->setContentsMargins(2, 2, 2, 2);
layout->setSpacing(0);
......@@ -91,13 +91,13 @@ KCalcBitset::KCalcBitset(QWidget *parent) : QFrame(parent), bit_button_group_(ne
for (int rows = 0; rows < 2; rows++) {
for (int cols = 0; cols < 4; cols++) {
// two rows of four words
QHBoxLayout *const wordlayout = new QHBoxLayout();
auto const wordlayout = new QHBoxLayout();
wordlayout->setContentsMargins(2, 2, 2, 2);
wordlayout->setSpacing(2);
layout->addLayout(wordlayout, rows, cols);
for (int bit = 0; bit < 8; bit++) {
BitButton *const tmpBitButton = new BitButton(this);
auto const tmpBitButton = new BitButton(this);
tmpBitButton->setToolTip(i18n("Bit %1 = %2", bitCounter, 1ULL << bitCounter));
wordlayout->addWidget(tmpBitButton);
bit_button_group_->addButton(tmpBitButton, bitCounter);
......@@ -105,7 +105,7 @@ KCalcBitset::KCalcBitset(QWidget *parent) : QFrame(parent), bit_button_group_(ne
}
// label word
QLabel *label = new QLabel(this);
auto label = new QLabel(this);
label->setText(QString::number(bitCounter + 1));
label->setFont(fnt);
wordlayout->addWidget(label);
......@@ -128,7 +128,7 @@ void KCalcBitset::setValue(quint64 value) {
// set each bit button
for (int i = 0; i < 64; i++) {
if(BitButton *bb = qobject_cast<BitButton*>(bit_button_group_->button(i))) {
if(auto bb = qobject_cast<BitButton*>(bit_button_group_->button(i))) {
bb->setOn(value & 1);
}
value >>= 1;
......
......@@ -92,12 +92,12 @@ void KCalcConstButton::setLabelAndTooltip() {
//------------------------------------------------------------------------------
void KCalcConstButton::initPopupMenu() {
QAction *const a = new QAction(this);
auto const a = new QAction(this);
a->setText(i18n("Set Name"));
connect(a, &QAction::triggered, this, &KCalcConstButton::slotConfigureButton);
addAction(a);
KCalcConstMenu *const tmp_menu = new KCalcConstMenu(this);
auto const tmp_menu = new KCalcConstMenu(this);
tmp_menu->menuAction()->setText(i18n("Choose From List"));
addAction(tmp_menu->menuAction());
setContextMenuPolicy(Qt::ActionsContextMenu);
......
......@@ -113,7 +113,7 @@ void KCalcConstMenu::init_all()
for (int i = 0; i < scienceConstantList.size(); i++) {
QAction *tmp_action = new QAction(i18n(scienceConstantList.at(i).name.toLatin1().data()), this);
auto tmp_action = new QAction(i18n(scienceConstantList.at(i).name.toLatin1().data()), this);
tmp_action->setData(QVariant(i));
if (scienceConstantList.at(i).category & Mathematics)
math_menu->addAction(tmp_action);
......
......@@ -36,7 +36,7 @@ KCalcStatusBar::KCalcStatusBar(QWidget *parent)
QLabel *KCalcStatusBar::addIndicator(QList<QString> indicatorTexts)
{
QLabel *l = new QLabel(indicatorTexts.at(0), this);
auto l = new QLabel(indicatorTexts.at(0), this);
// find widest indicator text
QFontMetrics fm(l->font());
......
......@@ -147,7 +147,7 @@ void round(QString &str, int precision) {
QString round(const QString &s, int precision) {
QString tmp = s;
if (precision < 0 || !QRegExp(QLatin1String("^[+-]?\\d+(\\.\\d+)*(e[+-]?\\d+)?$")).exactMatch(tmp)) {
if (precision < 0 || !QRegExp(QLatin1String(R"(^[+-]?\d+(\.\d+)*(e[+-]?\d+)?$)")).exactMatch(tmp)) {
return s;
}
......@@ -208,7 +208,7 @@ QString KNumber::decimalSeparator() {
//------------------------------------------------------------------------------
void KNumber::setDefaultFloatPrecision(int precision) {
// Need to transform decimal digits into binary digits
const unsigned long int bin_prec = static_cast<unsigned long int>(::ceil(precision * M_LN10 / M_LN2) + 1);
const auto bin_prec = static_cast<unsigned long int>(::ceil(precision * M_LN10 / M_LN2) + 1);
mpfr_set_default_prec(static_cast<mpfr_prec_t>(bin_prec));
}
......@@ -277,7 +277,7 @@ KNumber::KNumber(const QString &s) : value_(nullptr) {
const QRegExp special_regex(QLatin1String("^(inf|-inf|nan)$"));
const QRegExp integer_regex(QLatin1String("^[+-]?\\d+$"));
const QRegExp fraction_regex(QLatin1String("^[+-]?\\d+/\\d+$"));
const QRegExp float_regex(QString(QLatin1String("^([+-]?\\d*)(%1\\d*)?(e([+-]?\\d+))?$")).arg(QRegExp::escape(DecimalSeparator)));
const QRegExp float_regex(QString(QLatin1String(R"(^([+-]?\d*)(%1\d*)?(e([+-]?\d+))?$)")).arg(QRegExp::escape(DecimalSeparator)));
if (special_regex.exactMatch(s)) {
value_ = new detail::knumber_error(s);
......@@ -433,18 +433,18 @@ KNumber KNumber::integerPart() const {
KNumber x(*this);
if(detail::knumber_integer *const p = dynamic_cast<detail::knumber_integer *>(value_)) {
if(auto const p = dynamic_cast<detail::knumber_integer *>(value_)) {
// NO-OP
Q_UNUSED(p);
} else if(detail::knumber_float *const p = dynamic_cast<detail::knumber_float *>(value_)) {
} else if(auto const p = dynamic_cast<detail::knumber_float *>(value_)) {
detail::knumber_base *v = new detail::knumber_integer(p);
qSwap(v, x.value_);
delete v;
} else if(detail::knumber_fraction *const p = dynamic_cast<detail::knumber_fraction *>(value_)) {
} else if(auto const p = dynamic_cast<detail::knumber_fraction *>(value_)) {
detail::knumber_base *v = new detail::knumber_integer(p);
qSwap(v, x.value_);
delete v;
} else if(detail::knumber_error *const p = dynamic_cast<detail::knumber_error *>(value_)) {
} else if(auto const p = dynamic_cast<detail::knumber_error *>(value_)) {
// NO-OP
Q_UNUSED(p);
} else {
......@@ -461,18 +461,18 @@ void KNumber::simplify() {
if(value_->is_integer()) {
if(detail::knumber_integer *const p = dynamic_cast<detail::knumber_integer *>(value_)) {
if(auto const p = dynamic_cast<detail::knumber_integer *>(value_)) {
// NO-OP
Q_UNUSED(p);
} else if(detail::knumber_float *const p = dynamic_cast<detail::knumber_float *>(value_)) {
} else if(auto const p = dynamic_cast<detail::knumber_float *>(value_)) {
detail::knumber_base *v = new detail::knumber_integer(p);
qSwap(v, value_);
delete v;
} else if(detail::knumber_fraction *const p = dynamic_cast<detail::knumber_fraction *>(value_)) {
} else if(auto const p = dynamic_cast<detail::knumber_fraction *>(value_)) {
detail::knumber_base *v = new detail::knumber_integer(p);
qSwap(v, value_);
delete v;
} else if(detail::knumber_error *const p = dynamic_cast<detail::knumber_error *>(value_)) {
} else if(auto const p = dynamic_cast<detail::knumber_error *>(value_)) {
// NO-OP
Q_UNUSED(p);
} else {
......@@ -604,19 +604,19 @@ QString KNumber::toQString(int width, int precision) const {
QString s;
if(detail::knumber_integer *const p = dynamic_cast<detail::knumber_integer *>(value_)) {
if(auto const p = dynamic_cast<detail::knumber_integer *>(value_)) {
if(width > 0) {
s = detail::knumber_float(p).toString(width);
} else {
s = value_->toString(width);
}
} else if(detail::knumber_float *const p = dynamic_cast<detail::knumber_float *>(value_)) {
} else if(auto const p = dynamic_cast<detail::knumber_float *>(value_)) {
if(width > 0) {
s = value_->toString(width);
} else {
s = value_->toString(3 * mpf_get_default_prec() / 10);
}
} else if(detail::knumber_fraction *const p = dynamic_cast<detail::knumber_fraction *>(value_)) {
} else if(auto const p = dynamic_cast<detail::knumber_fraction *>(value_)) {
s = value_->toString(width);
} else {
return value_->toString(width);
......
......@@ -104,16 +104,16 @@ QString knumber_error::toString(int precision) const {
//------------------------------------------------------------------------------
knumber_base *knumber_error::add(knumber_base *rhs) {
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
if(auto const p = dynamic_cast<knumber_integer *>(rhs)) {
Q_UNUSED(p);
return this;
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_float *>(rhs)) {
Q_UNUSED(p);
return this;
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_fraction *>(rhs)) {
Q_UNUSED(p);
return this;
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_error *>(rhs)) {
if(error_ == ERROR_POS_INFINITY && p->error_ == ERROR_NEG_INFINITY) {
error_ = ERROR_UNDEFINED;
} else if(error_ == ERROR_NEG_INFINITY && p->error_ == ERROR_POS_INFINITY) {
......@@ -133,16 +133,16 @@ knumber_base *knumber_error::add(knumber_base *rhs) {
//------------------------------------------------------------------------------
knumber_base *knumber_error::sub(knumber_base *rhs) {
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
if(auto const p = dynamic_cast<knumber_integer *>(rhs)) {
Q_UNUSED(p);
return this;
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_float *>(rhs)) {
Q_UNUSED(p);
return this;
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_fraction *>(rhs)) {
Q_UNUSED(p);
return this;
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_error *>(rhs)) {
if(error_ == ERROR_POS_INFINITY && p->error_ == ERROR_POS_INFINITY) {
error_ = ERROR_UNDEFINED;
} else if(error_ == ERROR_NEG_INFINITY && p->error_ == ERROR_NEG_INFINITY) {
......@@ -162,22 +162,22 @@ knumber_base *knumber_error::sub(knumber_base *rhs) {
//------------------------------------------------------------------------------
knumber_base *knumber_error::mul(knumber_base *rhs) {
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
if(auto const p = dynamic_cast<knumber_integer *>(rhs)) {
if(p->is_zero()) {
error_ = ERROR_UNDEFINED;
}
return this;
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_float *>(rhs)) {
if(p->is_zero()) {
error_ = ERROR_UNDEFINED;
}
return this;
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_fraction *>(rhs)) {
if(p->is_zero()) {
error_ = ERROR_UNDEFINED;
}
return this;
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_error *>(rhs)) {
if(error_ == ERROR_POS_INFINITY && p->error_ == ERROR_NEG_INFINITY) {
error_ = ERROR_NEG_INFINITY;
} else if(error_ == ERROR_NEG_INFINITY && p->error_ == ERROR_POS_INFINITY) {
......@@ -199,16 +199,16 @@ knumber_base *knumber_error::mul(knumber_base *rhs) {
//------------------------------------------------------------------------------
knumber_base *knumber_error::div(knumber_base *rhs) {
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
if(auto const p = dynamic_cast<knumber_integer *>(rhs)) {
Q_UNUSED(p);
return this;
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_float *>(rhs)) {
Q_UNUSED(p);
return this;
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_fraction *>(rhs)) {
Q_UNUSED(p);
return this;
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_error *>(rhs)) {
Q_UNUSED(p);
error_ = ERROR_UNDEFINED;
return this;
......@@ -223,16 +223,16 @@ knumber_base *knumber_error::div(knumber_base *rhs) {
//------------------------------------------------------------------------------
knumber_base *knumber_error::mod(knumber_base *rhs) {
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
if(auto const p = dynamic_cast<knumber_integer *>(rhs)) {
Q_UNUSED(p);
return this;
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_float *>(rhs)) {
Q_UNUSED(p);
return this;
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_fraction *>(rhs)) {
Q_UNUSED(p);
return this;
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_error *>(rhs)) {
Q_UNUSED(p);
error_ = ERROR_UNDEFINED;
return this;
......@@ -247,23 +247,23 @@ knumber_base *knumber_error::mod(knumber_base *rhs) {
//------------------------------------------------------------------------------
knumber_base *knumber_error::pow(knumber_base *rhs) {
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
if(auto const p = dynamic_cast<knumber_integer *>(rhs)) {
Q_UNUSED(p);
return this;
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_float *>(rhs)) {
Q_UNUSED(p);
return this;
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_fraction *>(rhs)) {
Q_UNUSED(p);
return this;
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_error *>(rhs)) {
switch(error_) {
case ERROR_POS_INFINITY:
if(p->sign() > 0) {
return this;
} else if(p->sign() < 0) {
knumber_integer *n = new knumber_integer(0);
auto n = new knumber_integer(0);
delete this;
return n;
} else {
......@@ -276,7 +276,7 @@ knumber_base *knumber_error::pow(knumber_base *rhs) {
error_ = ERROR_POS_INFINITY;
return this;
} else if(p->sign() < 0) {
knumber_integer *n = new knumber_integer(0);
auto n = new knumber_integer(0);
delete this;
return n;
} else {
......@@ -513,25 +513,25 @@ knumber_base *knumber_error::atanh() {
//------------------------------------------------------------------------------
int knumber_error::compare(knumber_base *rhs) {
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
if(auto const p = dynamic_cast<knumber_integer *>(rhs)) {
if(sign() > 0) {
return 1;
} else {
return -1;
}
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_float *>(rhs)) {
if(sign() > 0) {
return 1;
} else {
return -1;
}
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_fraction *>(rhs)) {
if(sign() > 0) {
return 1;
} else {
return -1;
}
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_error *>(rhs)) {
return sign() == p->sign();
}
......
......@@ -45,11 +45,11 @@ const mpfr_prec_t knumber_float::precision = 1024;
knumber_base *knumber_float::ensureIsValid(mpfr_ptr mpfr) {
if (mpfr_nan_p(mpfr)) {
knumber_error *e = new knumber_error(knumber_error::ERROR_UNDEFINED);
auto e = new knumber_error(knumber_error::ERROR_UNDEFINED);
delete this;
return e;
} else if (mpfr_inf_p(mpfr)) {
knumber_error *e = new knumber_error(knumber_error::ERROR_POS_INFINITY);
auto e = new knumber_error(knumber_error::ERROR_POS_INFINITY);
delete this;
return e;
} else {
......@@ -160,17 +160,17 @@ knumber_float::~knumber_float() {
//------------------------------------------------------------------------------
knumber_base *knumber_float::add(knumber_base *rhs) {
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
if(auto const p = dynamic_cast<knumber_integer *>(rhs)) {
knumber_float f(p);
return add(&f);
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_float *>(rhs)) {
mpfr_add(mpfr_, mpfr_, p->mpfr_, rounding_mode);
return this;
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_fraction *>(rhs)) {
knumber_float f(p);
return add(&f);
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
knumber_error *e = new knumber_error(p);
} else if(auto const p = dynamic_cast<knumber_error *>(rhs)) {
auto e = new knumber_error(p);
delete this;
return e;
}
......@@ -184,17 +184,17 @@ knumber_base *knumber_float::add(knumber_base *rhs) {
//------------------------------------------------------------------------------
knumber_base *knumber_float::sub(knumber_base *rhs) {
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
if(auto const p = dynamic_cast<knumber_integer *>(rhs)) {
knumber_float f(p);
return sub(&f);
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_float *>(rhs)) {
mpfr_sub(mpfr_, mpfr_, p->mpfr_, rounding_mode);
return this;
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_fraction *>(rhs)) {
knumber_float f(p);
return sub(&f);
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
knumber_error *e = new knumber_error(p);
} else if(auto const p = dynamic_cast<knumber_error *>(rhs)) {
auto e = new knumber_error(p);
delete this;
return e->neg();
}
......@@ -208,16 +208,16 @@ knumber_base *knumber_float::sub(knumber_base *rhs) {
//------------------------------------------------------------------------------
knumber_base *knumber_float::mul(knumber_base *rhs) {
if(knumber_integer *const p = dynamic_cast<knumber_integer *>(rhs)) {
if(auto const p = dynamic_cast<knumber_integer *>(rhs)) {
knumber_float f(p);
return mul(&f);
} else if(knumber_float *const p = dynamic_cast<knumber_float *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_float *>(rhs)) {
mpfr_mul(mpfr_, mpfr_, p->mpfr_, rounding_mode);
return this;
} else if(knumber_fraction *const p = dynamic_cast<knumber_fraction *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_fraction *>(rhs)) {
knumber_float f(p);
return mul(&f);
} else if(knumber_error *const p = dynamic_cast<knumber_error *>(rhs)) {
} else if(auto const p = dynamic_cast<knumber_error *>(rhs)) {
if(is_zero()) {
delete this;
return new knumber_error(knumber_error::ERROR_UNDEFINED);
......@@ -225,7 +225,7 @@ knumber_base *knumber_float::mul(knumber_base *rhs) {
if(sign() < 0) {
delete this;
knumber_error *e = new knumber_error(p);
auto e = new knumber_error(p);
return e->neg();
} else {
delete this;
......@@ -252,16 +252,16 @@ knumber_base *knumber_float::div(knumber_base *rhs) {