Skip to content

Commit

Permalink
Remove unnecessary multiplication sign before unit expressions (e.g. …
Browse files Browse the repository at this point in the history
…5x*m/s); sin(x*pi) and tan(x*pi) equals zero if x represents an integer; Fix set color with named colors (e.g. "light"); Fix placement (last) of constant of definite integral; Update exchange rates; Increment version number
  • Loading branch information
hanna-kn committed Jun 11, 2020
1 parent 48f4cf4 commit 935a2a6
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 72 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2019-06-08 Hanna Knutsson <[email protected]>

* Fix placement (last) of constant of definite integral
* sin(x*pi) and tan(x*pi) equals zero if x represents an integer

2019-06-05 Hanna Knutsson <[email protected]>

* Fix segfault when parsing an expression that contains a prefix with more than one letter and a unit exponent (2 or 3) without exponentiation operator, e.g. dam3

2019-06-01 Hanna Knutsson <[email protected]>

* Fix use of equals sign in qalc command line arguments (e.g. "qalc --base=16")
Expand Down
6 changes: 3 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dnl ----------------------
dnl | initialize autotools |---------------------------------------------------
dnl ----------------------

AC_INIT([libqalculate], [3.10.0])
AC_INIT([libqalculate], [3.11.0])
AC_CONFIG_SRCDIR(libqalculate/Calculator.cc)
AM_INIT_AUTOMAKE
AM_CONFIG_HEADER(config.h)
Expand Down Expand Up @@ -80,7 +80,7 @@ AC_DEFINE([HAVE_PTHREADS],1,
dnl libtool versioning for libqalculate

dnl increment if the interface has additions, changes, removals.
QALCULATE_CURRENT=29
QALCULATE_CURRENT=30

dnl increment any time the source changes; set to
dnl 0 if you increment CURRENT
Expand All @@ -89,7 +89,7 @@ QALCULATE_REVISION=0
dnl increment if any interfaces have been added; set to 0
dnl if any interfaces have been removed. removal has
dnl precedence over adding, so set to 0 if both happened.
QALCULATE_AGE=8
QALCULATE_AGE=9

AC_SUBST(QALCULATE_CURRENT)
AC_SUBST(QALCULATE_REVISION)
Expand Down
64 changes: 32 additions & 32 deletions data/eurofxref-daily.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@
<gesmes:name>European Central Bank</gesmes:name>
</gesmes:Sender>
<Cube>
<Cube time='2020-05-04'>
<Cube currency='USD' rate='1.0942'/>
<Cube currency='JPY' rate='116.84'/>
<Cube time='2020-06-10'>
<Cube currency='USD' rate='1.1375'/>
<Cube currency='JPY' rate='122.16'/>
<Cube currency='BGN' rate='1.9558'/>
<Cube currency='CZK' rate='27.119'/>
<Cube currency='DKK' rate='7.4622'/>
<Cube currency='GBP' rate='0.87898'/>
<Cube currency='HUF' rate='353.27'/>
<Cube currency='PLN' rate='4.5668'/>
<Cube currency='RON' rate='4.8368'/>
<Cube currency='SEK' rate='10.8113'/>
<Cube currency='CHF' rate='1.0548'/>
<Cube currency='ISK' rate='159.50'/>
<Cube currency='NOK' rate='11.3280'/>
<Cube currency='HRK' rate='7.5820'/>
<Cube currency='RUB' rate='82.3404'/>
<Cube currency='TRY' rate='7.6932'/>
<Cube currency='AUD' rate='1.7022'/>
<Cube currency='BRL' rate='6.0781'/>
<Cube currency='CAD' rate='1.5390'/>
<Cube currency='CNY' rate='7.7275'/>
<Cube currency='HKD' rate='8.4838'/>
<Cube currency='IDR' rate='16522.42'/>
<Cube currency='ILS' rate='3.8581'/>
<Cube currency='INR' rate='82.7870'/>
<Cube currency='KRW' rate='1340.00'/>
<Cube currency='MXN' rate='26.8862'/>
<Cube currency='MYR' rate='4.7226'/>
<Cube currency='NZD' rate='1.8083'/>
<Cube currency='PHP' rate='55.379'/>
<Cube currency='SGD' rate='1.5495'/>
<Cube currency='THB' rate='35.397'/>
<Cube currency='ZAR' rate='20.3924'/>
<Cube currency='CZK' rate='26.609'/>
<Cube currency='DKK' rate='7.4553'/>
<Cube currency='GBP' rate='0.88963'/>
<Cube currency='HUF' rate='343.13'/>
<Cube currency='PLN' rate='4.4524'/>
<Cube currency='RON' rate='4.8349'/>
<Cube currency='SEK' rate='10.4605'/>
<Cube currency='CHF' rate='1.0762'/>
<Cube currency='ISK' rate='150.70'/>
<Cube currency='NOK' rate='10.5383'/>
<Cube currency='HRK' rate='7.5690'/>
<Cube currency='RUB' rate='78.1468'/>
<Cube currency='TRY' rate='7.7145'/>
<Cube currency='AUD' rate='1.6220'/>
<Cube currency='BRL' rate='5.5213'/>
<Cube currency='CAD' rate='1.5228'/>
<Cube currency='CNY' rate='8.0305'/>
<Cube currency='HKD' rate='8.8157'/>
<Cube currency='IDR' rate='16022.03'/>
<Cube currency='ILS' rate='3.9045'/>
<Cube currency='INR' rate='85.9030'/>
<Cube currency='KRW' rate='1352.17'/>
<Cube currency='MXN' rate='24.8255'/>
<Cube currency='MYR' rate='4.8361'/>
<Cube currency='NZD' rate='1.7357'/>
<Cube currency='PHP' rate='56.767'/>
<Cube currency='SGD' rate='1.5746'/>
<Cube currency='THB' rate='35.422'/>
<Cube currency='ZAR' rate='18.8376'/>
</Cube>
</Cube>
</gesmes:Envelope>
2 changes: 1 addition & 1 deletion docs/reference/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places.
# The default value is: My Project.

PROJECT_NAME = libqalculate-3.10.0
PROJECT_NAME = libqalculate-3.11.0

# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version
Expand Down
30 changes: 30 additions & 0 deletions libqalculate/BuiltinFunctions-trigonometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,21 @@ int SinFunction::calculate(MathStructure &mstruct, const MathStructure &vargs, c
}
}
}
} else if(mstruct.isMultiplication() && mstruct.size() >= 2) {
bool b_pi = false;
for(size_t i = 0; i < mstruct.size(); i++) {
if(mstruct[i].isVariable() && mstruct[i].variable()->id() == VARIABLE_ID_PI) {
b_pi = !b_pi;
if(!b_pi) break;
} else if(!mstruct[i].representsInteger()) {
b_pi = false;
break;
}
}
if(b_pi) {
mstruct.clear();
b = true;
}
} else if(mstruct.isAddition()) {
size_t i = 0;
bool b_negate = false;
Expand Down Expand Up @@ -795,6 +810,21 @@ int TanFunction::calculate(MathStructure &mstruct, const MathStructure &vargs, c
}
}
}
} else if(mstruct.isMultiplication() && mstruct.size() >= 2) {
bool b_pi = false;
for(size_t i = 0; i < mstruct.size(); i++) {
if(mstruct[i].isVariable() && mstruct[i].variable()->id() == VARIABLE_ID_PI) {
b_pi = !b_pi;
if(!b_pi) break;
} else if(!mstruct[i].representsInteger()) {
b_pi = false;
break;
}
}
if(b_pi) {
mstruct.clear();
b = true;
}
} else if(mstruct.isAddition()) {
size_t i = 0;
for(; i < mstruct.size(); i++) {
Expand Down
2 changes: 1 addition & 1 deletion libqalculate/Calculator-definitions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ int Calculator::loadDefinitions(const char* file_name, bool is_user_defs, bool c
xmlFreeDoc(doc);
return false;
}
int version_numbers[] = {3, 10, 0};
int version_numbers[] = {3, 11, 0};
parse_qalculate_version(version, version_numbers);

bool new_names = version_numbers[0] > 0 || version_numbers[1] > 9 || (version_numbers[1] == 9 && version_numbers[2] >= 4);
Expand Down
20 changes: 10 additions & 10 deletions libqalculate/Calculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ Calculator::Calculator() {
srand(time(NULL));

exchange_rates_time[0] = 0;
exchange_rates_time[1] = (time_t) 441284L * (time_t) 3600;
exchange_rates_time[1] = (time_t) 442176L * (time_t) 3600;
exchange_rates_time[2] = 0;
priv->exchange_rates_time2[0] = (time_t) 441284L * (time_t) 3600;
priv->exchange_rates_time2[0] = (time_t) 442176L * (time_t) 3600;
exchange_rates_check_time[0] = 0;
exchange_rates_check_time[1] = (time_t) 441284L * (time_t) 3600;
exchange_rates_check_time[1] = (time_t) 442176L * (time_t) 3600;
exchange_rates_check_time[2] = 0;
priv->exchange_rates_check_time2[0] = (time_t) 441284L * (time_t) 3600;
priv->exchange_rates_check_time2[0] = (time_t) 442176L * (time_t) 3600;
b_exchange_rates_warning_enabled = true;
b_exchange_rates_used = 0;

Expand Down Expand Up @@ -409,13 +409,13 @@ Calculator::Calculator(bool ignore_locale) {
srand(time(NULL));

exchange_rates_time[0] = 0;
exchange_rates_time[1] = (time_t) 441284L * (time_t) 3600;
exchange_rates_time[1] = (time_t) 442176L * (time_t) 3600;
exchange_rates_time[2] = 0;
priv->exchange_rates_time2[0] = (time_t) 441284L * (time_t) 3600;
priv->exchange_rates_time2[0] = (time_t) 442176L * (time_t) 3600;
exchange_rates_check_time[0] = 0;
exchange_rates_check_time[1] = (time_t) 441284L * (time_t) 3600;
exchange_rates_check_time[1] = (time_t) 442176L * (time_t) 3600;
exchange_rates_check_time[2] = 0;
priv->exchange_rates_check_time2[0] = (time_t) 441284L * (time_t) 3600;
priv->exchange_rates_check_time2[0] = (time_t) 442176L * (time_t) 3600;
b_exchange_rates_warning_enabled = true;
b_exchange_rates_used = 0;

Expand Down Expand Up @@ -1701,11 +1701,11 @@ void Calculator::addBuiltinFunctions() {
}
void Calculator::addBuiltinUnits() {
u_euro = addUnit(new Unit(_("Currency"), "EUR", "euros", "euro", "European Euros", false, true, true));
u_btc = addUnit(new AliasUnit(_("Currency"), "BTC", "bitcoins", "bitcoin", "Bitcoins", u_euro, "8290.26", 1, "", false, true, true));
u_btc = addUnit(new AliasUnit(_("Currency"), "BTC", "bitcoins", "bitcoin", "Bitcoins", u_euro, "8611.10", 1, "", false, true, true));
u_btc->setApproximate();
u_btc->setPrecision(-2);
u_btc->setChanged(false);
priv->u_byn = addUnit(new AliasUnit(_("Currency"), "BYN", "", "", "Belarusian Ruble", u_euro, "2.6845", 1, "", false, true, true));
priv->u_byn = addUnit(new AliasUnit(_("Currency"), "BYN", "", "", "Belarusian Ruble", u_euro, "2.6941", 1, "", false, true, true));
priv->u_byn->setApproximate();
priv->u_byn->setPrecision(-2);
priv->u_byn->setChanged(false);
Expand Down
47 changes: 26 additions & 21 deletions libqalculate/MathStructure-print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,31 @@ int sortCompare(const MathStructure &mstruct1, const MathStructure &mstruct2, co
return sortCompare(mstruct1[0], mstruct2[0], parent, po);
}
}
if(parent.isAddition() && po.sort_options.minus_last) {
// -a+b=b-a
bool m1 = mstruct1.hasNegativeSign(), m2 = mstruct2.hasNegativeSign();
if(m1 && !m2) {
return 1;
} else if(m2 && !m1) {
return -1;
if(parent.isAddition()) {

// always place constant of definite integral last
if(mstruct1.isVariable() && mstruct1.variable() == CALCULATOR->getVariableById(VARIABLE_ID_C)) return 1;
if(mstruct2.isVariable() && mstruct2.variable() == CALCULATOR->getVariableById(VARIABLE_ID_C)) return -1;

if(po.sort_options.minus_last) {
// -a+b=b-a
bool m1 = mstruct1.hasNegativeSign(), m2 = mstruct2.hasNegativeSign();
if(m1 && !m2) {
return 1;
} else if(m2 && !m1) {
return -1;
}
}

if((mstruct1.isUnit() || (mstruct1.isMultiplication() && mstruct1.size() == 2 && mstruct1[1].isUnit())) && (mstruct2.isUnit() || (mstruct2.isMultiplication() && mstruct2.size() == 2 && mstruct2[1].isUnit()))) {
Unit *u1, *u2;
if(mstruct1.isUnit()) u1 = mstruct1.unit();
else u1 = mstruct1[1].unit();
if(mstruct2.isUnit()) u2 = mstruct2.unit();
else u2 = mstruct2[1].unit();
if(u1->isParentOf(u2)) return 1;
if(u2->isParentOf(u1)) return -1;
}
}
if(parent.isAddition() && (mstruct1.isUnit() || (mstruct1.isMultiplication() && mstruct1.size() == 2 && mstruct1[1].isUnit())) && (mstruct2.isUnit() || (mstruct2.isMultiplication() && mstruct2.size() == 2 && mstruct2[1].isUnit()))) {
Unit *u1, *u2;
if(mstruct1.isUnit()) u1 = mstruct1.unit();
else u1 = mstruct1[1].unit();
if(mstruct2.isUnit()) u2 = mstruct2.unit();
else u2 = mstruct2[1].unit();
if(u1->isParentOf(u2)) return 1;
if(u2->isParentOf(u1)) return -1;
}
bool isdiv1 = false, isdiv2 = false;
if(!po.negative_exponents) {
Expand Down Expand Up @@ -179,9 +187,6 @@ int sortCompare(const MathStructure &mstruct1, const MathStructure &mstruct2, co
}
}
}
// always place constant of definite integral last
if(mstruct1.isVariable() && mstruct1.variable() == CALCULATOR->getVariableById(VARIABLE_ID_C)) return 1;
if(mstruct2.isVariable() && mstruct2.variable() == CALCULATOR->getVariableById(VARIABLE_ID_C)) return -1;
if(mstruct1.type() != mstruct2.type()) {
if(mstruct1.isVariable() && mstruct2.isSymbolic()) {
if(parent.isMultiplication()) {
Expand Down Expand Up @@ -2788,7 +2793,7 @@ int MathStructure::neededMultiplicationSign(const PrintOptions &po, const Intern
int namelen_this = namelen(*this, po, ips, &abbr_this);
int namelen_prev = namelen(parent[index - 2], po, ips, &abbr_prev);
switch(t) {
case STRUCT_MULTIPLICATION: {return MULTIPLICATION_SIGN_OPERATOR;}
case STRUCT_MULTIPLICATION: {break;}
case STRUCT_INVERSE: {}
case STRUCT_DIVISION: {if(flat_division) return MULTIPLICATION_SIGN_OPERATOR; return MULTIPLICATION_SIGN_SPACE;}
case STRUCT_ADDITION: {return MULTIPLICATION_SIGN_OPERATOR;}
Expand Down Expand Up @@ -2832,7 +2837,7 @@ int MathStructure::neededMultiplicationSign(const PrintOptions &po, const Intern
default: {return MULTIPLICATION_SIGN_OPERATOR;}
}
switch(m_type) {
case STRUCT_MULTIPLICATION: {return MULTIPLICATION_SIGN_OPERATOR;}
case STRUCT_MULTIPLICATION: {return MULTIPLICATION_SIGN_SPACE;}
case STRUCT_INVERSE: {}
case STRUCT_DIVISION: {return MULTIPLICATION_SIGN_SPACE;}
case STRUCT_ADDITION: {return MULTIPLICATION_SIGN_OPERATOR;}
Expand Down
2 changes: 1 addition & 1 deletion libqalculate/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <stdint.h>

#define QALCULATE_MAJOR_VERSION (3)
#define QALCULATE_MINOR_VERSION (10)
#define QALCULATE_MINOR_VERSION (11)
#define QALCULATE_MICRO_VERSION (0)

static std::string empty_string;
Expand Down
6 changes: 3 additions & 3 deletions src/qalc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,8 @@ void set_option(string str) {
else if(EQUALS_IGNORECASE_AND_LOCAL(svar, "color", _("color"))) {
int v = -1;
// light color
if(svalue == "2" || EQUALS_IGNORECASE_AND_LOCAL(svar, "light", _("light"))) v = 2;
else if(svalue == "1" || EQUALS_IGNORECASE_AND_LOCAL(svar, "default", _("default"))) v = 1;
if(svalue == "2" || EQUALS_IGNORECASE_AND_LOCAL(svalue, "light", _("light"))) v = 2;
else if(svalue == "1" || EQUALS_IGNORECASE_AND_LOCAL(svalue, "default", _("default"))) v = 1;
else v = s2b(svalue);
if(v < 0 || v > 2) {
PUTS_UNICODE(_("Illegal value."));
Expand Down Expand Up @@ -5574,7 +5574,7 @@ void load_preferences() {
#endif


int version_numbers[] = {3, 10, 0};
int version_numbers[] = {3, 11, 0};

if(file) {
char line[10000];
Expand Down

0 comments on commit 935a2a6

Please sign in to comment.