Giter Site home page Giter Site logo

qalculate / libqalculate Goto Github PK

View Code? Open in Web Editor NEW
1.7K 21.0 143.0 26.71 MB

Qalculate! library and CLI

Home Page: https://qalculate.github.io/

License: GNU General Public License v2.0

Shell 0.39% M4 2.08% C++ 77.19% C 20.25% Makefile 0.09% sed 0.01%

libqalculate's Introduction

libqalculate

Qalculate! library and CLI

Image of qalc

Qalculate! is a multi-purpose cross-platform desktop calculator. It is simple to use but provides power and versatility normally reserved for complicated math packages, as well as useful tools for everyday needs (such as currency conversion and percent calculation). Features include a large library of customizable functions, unit calculations and conversion, symbolic calculations (including integrals and equations), arbitrary precision, uncertainty propagation, interval arithmetic, plotting, and a user-friendly interface (GTK+, Qt, and CLI).

Requirements

  • GMP and MPFR
  • libxml2
  • libcurl, icu, gettext (recommended)
  • iconv, readline (recommended for CLI)
  • Gnuplot (optional)
  • doxygen (for compilation of git version)

For Linux distributions which provide separate development packages, these must be installed for all the required libraries (e.g. libmpfr-dev) before compilation.

Installation

Instructions and download links for installers, binaries packages, and the source code of released versions of Qalculate! are available at https://qalculate.github.io/downloads.html.

In a terminal window in the top source code directory run

  • ./autogen.sh (not required if using a release source tarball, only if using the git version)
  • ./configure
  • make
  • make install (as root, e.g. sudo make install)
  • ldconfig (if necessary, as root)

If libqalculate is installed in /usr/local (default) you may need to add /usr/local/lib to the library path of the system (add /usr/local/lib to a file under /etc/ld.so.conf.d/ and run ldconfig).

API Documentation

The API documentation is included in the package and is installed in $docdir/libqalculate/html (usually /usr/share/doc/libqalculate/html). It is generated when running autogen.sh.

It is also available online at http://qalculate.github.io/reference/index.html.

Using the CLI program 'qalc'

To calculate a single expression from the command line (non-interactive mode) enter qalc mathematical expression (e.g. qalc 5+2)

qalc --help shows information about command line options in non-interactive mode.

If you run qalc without any mathematical expression the program will start in interactive mode, where you can enter multiple expressions with history and completion, manipulate the result and change settings. Type help in interactive mode for more information.

A man page is also available (shown using the command man qalc, or online at https://qalculate.github.io/manual/qalc.html).

Other Applications

The main user interfaces for libqalculate are qalculate-gtk (https://github.com/Qalculate/qalculate-gtk) and qalculate-qt (https://github.com/Qalculate/qalculate-qt).

Other software using libqalculate include

Features

  • Calculation and parsing:
    • Basic operations and operators: + - * / mod ^ E () && || ! < > >= <= != ~ & | << >> xor
    • Fault-tolerant parsing of strings: log 5 / 2 .5 (3) + (2( 3 +5 = ln(5) / (2.5 * 3) + 2 * (3 + 5)
    • Expressions may contain any combination of numbers, functions, units, variables, vectors and matrices, and dates
    • Supports complex and infinite numbers
    • Propagation of uncertainty
    • Interval arithmetic (for determination of the number of significant digits or direct calculation with intervals of numbers)
    • Supports all common number bases, as well as negative and non-integer radices, sexagesimal numbers, time format, and roman numerals
    • Ability to disable functions, variables, units or unknown variables for less confusion: e.g. when you do not want (a+b)^2 to mean (are+barn)^2 but ("a"+"b")^2
    • Controllable implicit multiplication
    • Matrices and vectors, and related operations (determinants etc.)
    • Verbose error messages
    • Arbitrary precision
    • RPN mode
  • Result display:
    • Supports all common number bases, as well as negative and non-integer radices, sexagesimal numbers, time format, and roman numerals
    • Many customization options: precision, max/min decimals, complex form, multiplication sign, etc.
    • Exact or approximate: sqrt(32) returns 4 * sqrt(2) or 5.66
    • Simple and mixed fractions: 4 / 6 * 2 = 1.333... = 4/3 = 1 + 1/3
  • Symbolic calculation:
    • E.g. (x + y)^2 = x^2 + 2xy + y^2; 4 "apples" + 3 "oranges"
    • Factorization and simplification
    • Differentiation and integration
    • Can solve most equations and inequalities
    • Customizable assumptions give different results (e.g. ln(2x) = ln(2) + ln(x) if x is assumed positive)
  • Functions:
    • Hundreds of flexible functions: trigonometry, exponents and logarithms, combinatorics, geometry, calculus, statistics, finance, time and date, etc.
    • Can easily be created, edited and saved to a standard XML file
  • Units:
    • Supports all SI units and prefixes (including binary), as well as imperial and other unit systems
    • Automatic conversion: ft + yd + m = 2.2192 m
    • Explicit conversion: 5 m/s to mi/h = 11.18 miles/hour
    • Smart conversion: automatically converts 5 kg*m/s^2 to 5 N
    • Currency conversion with retrieval of daily exchange rates
    • Different name forms: abbreviation, singular, plural (m, meter, meters)
    • Can easily be created, edited and saved to a standard XML file
  • Variables and constants:
    • Basic constants: pi, e, etc.
    • Lots of physical constants (with or without units) and properties of chemical element
    • CSV file import and export
    • Can easily be created, edited and saved to a standard XML file
    • Flexible - may contain simple numbers, units, or whole expressions
    • Data sets with objects and associated properties in database-like structure
  • Plotting:
    • Uses Gnuplot
    • Can plot functions or data (matrices and vectors)
    • Ability to save plot to PNG image, postscript, etc.
    • Several customization options
  • and more...

For more details about the syntax, and available functions, units, and variables, please consult the manual (https://qalculate.github.io/manual/)

Examples (expressions)

Note that semicolon can be replaced with comma in function arguments, if comma is not used as decimal or thousands separator.

Basic functions and operators

sqrt 4 = sqrt(4) = 4^(0.5) = 4^(1/2) = 2

sqrt(25; 16; 9; 4) = [5 4 3 2]

sqrt(32) = 4 × √(2) (in exact mode)

cbrt(−27) = root(-27; 3) = −3 (real root)

(−27)^(1/3) ≈ 1.5 + 2.5980762i (principal root)

ln 25 = log(25; e) ≈ 3.2188758

log2(4)/log10(100) = log(4; 2)/log(100; 10) = 1

5! = 1 × 2 × 3 × 4 × 5 = 120

5\2 = 5//2 = trunc(5 / 2) = 2 (integer division)

5 mod 3 = mod(5; 3) = 2

52 to factors = 2^2 × 13

25/4 × 3/5 to fraction = 3 + 3/4

gcd(63; 27) = 9

sin(pi/2) − cos(pi) = sin(90 deg) − cos(180 deg) = 2

sum(x; 1; 5) = 1 + 2 + 3 + 4 + 5 = 15

sum(\i^2+sin(\i); 1; 5; \i) = 1^2 + sin(1) + 2^2 + sin(2) + ... ≈ 55.176162

product(x; 1; 5) = 1 × 2 × 3 × 4 × 5 = 120

var1:=5 (stores value 5 in variable var1) var1 × 2 = 10

5^2 #this is a comment = 25

sinh(0.5) where sinh()=cosh() = cosh(0.5) ≈ 1.1276260

plot(x^2; −5; 5) (plots the function y=x^2 from -5 to 5)

Units

5 dm3 to L = 5 dm^3 to L = 5 L

20 miles / 2h to km/h = 16.09344 km/h

1.74 to ft = 1.74 m to ft ≈ 5 ft + 8.5039370 in

1.74 m to -ft ≈ 5.7086614 ft

100 lbf × 60 mph to hp ≈ 16 hp

50 Ω × 2 A = 100 V

50 Ω × 2 A to base = 100 kg·m²/(s³·A)

10 N / 5 Pa = (10 N)/(5 Pa) = 2 m²

5 m/s to s/m = 0.2 s/m

500 € − 20% to $ ≈ $451.04

500 megabit/s × 2 h to b?byte ≈ 419.09516 gibibytes

Physical constants

k_e / G × a_0 = (coulombs_constant / newtonian_constant) × bohr_radius ≈ 7.126e9 kg·H·m^−1

ℎ / (λ_C × c) = planck ∕ (compton_wavelength × speed_of_light) ≈ 9.1093837e-31 kg

5 ns × rydberg to c ≈ 6.0793194E-8c

atom(Hg; weight) + atom(C; weight) × 4 to g ≈ 4.129e-22 g

(G × planet(earth; mass) × planet(mars; mass))/(54.6e6 km)^2 ≈ 8.58e16 N (gravitational attraction between earth and mars)

Uncertainty and interval arithmetic

"±" can be replaced with "+/-"; result with interval arithmetic activated is shown in parenthesis

sin(5±0.2)^2/2±0.3 ≈ 0.460±0.088 (0.46±0.12)

(2±0.02 J)/(523±5 W) ≈ 3.824±0.053 ms (3.825±0.075 ms)

interval(−2; 5)^2 ≈ intervall(−8.2500000; 12.750000) (intervall(0; 25))

Algebra

(5x^2 + 2)/(x − 3) = 5x + 15 + 47/(x − 3)

(\a + \b)(\a − \b) = ("a" + "b")("a" − "b") = 'a'^2 − 'b'^2

(x + 2)(x − 3)^3 = x^4 − 7x^3 + 9x^2 + 27x − 54

factorize x^4 − 7x^3 + 9x^2 + 27x − 54 = x^4 − 7x^3 + 9x^2 + 27x − 54 to factors = (x + 2)(x − 3)^3

cos(x)+3y^2 where x=pi and y=2 = 11

gcd(25x; 5x^2) = 5x

1/(x^2+2x−3) to partial fraction = 1/(4x − 4) − 1/(4x + 12)

x+x^2+4 = 16 = (x = 3 or x = −4)

x^2/(5 m) − hypot(x; 4 m) = 2 m where x > 0 = (x ≈ 7.1340411 m)

cylinder(20cm; x) = 20L (calculates the height of a 20 L cylinder with radius of 20 cm) = (x = (1 / (2π)) m) = (x ≈ 16 cm)

asin(sqrt(x)) = 0.2 = (x = sin(0.2)^2) = (x ≈ 0.039469503)

x^2 > 25x = (x > 25 or x < 0)

solve(x = y+ln(y); y) = lambertw(e^x)

solve2(5x=2y^2; sqrt(y)=2; x; y) = 32/5

multisolve([5x=2y+32, y=2z, z=2x]; [x, y, z]) = [−32/3 −128/3 −64/3]

dsolve(diff(y; x) − 2y = 4x; 5) = 6e^(2x) − 2x − 1

Calculus

diff(6x^2) = 12x

diff(sinh(x^2)/(5x) + 3xy/sqrt(x)) = (2/5) × cosh(x^2) − sinh(x^2)/(5x^2) + (3y)/(2 × √(x))

integrate(6x^2) = 2x^3 + C

integrate(6x^2; 1; 5) = 248

integrate(sinh(x^2)/(5x) + 3xy/sqrt(x)) = 2x × √(x) × y + Shi(x^2) / 10 + C

integrate(sinh(x^2)/(5x) + 3xy/sqrt(x); 1; 2) ≈ 3.6568542y + 0.87600760

limit(ln(1 + 4x)/(3^x − 1); 0) = 4 / ln(3)

Matrices and vectors

[1, 2, 3; 4, 5, 6] = ((1; 2; 3); (4; 5; 6)) = [1 2 3; 4 5 6] (2×3 matrix)

1...5 = (1:5) = (1:1:5) = [1 2 3 4 5]

(1; 2; 3) × 2 − 2 = [(1 × 2 − 2), (2 × 2 − 2), (3 × 2 − 2)] = [0 2 4]

[1 2 3].[4 5 6] = dot([1 2 3]; [4 5 6]) = 32 (dot product)

cross([1 2 3]; [4 5 6]) = [−3 6 −3] (cross product)

[1 2 3; 4 5 6].×[7 8 9; 10 11 12] = hadamard([1 2 3; 4 5 6]; [7 8 9; 10 11 12]) = [7 16 27; 40 55 72] (hadamard product)

[1 2 3; 4 5 6] × [7 8; 9 10; 11 12] = [58 64; 139 154] (matrix multiplication)

[1 2; 3 4]^-1 = inverse([1 2; 3 4]) = [−2 1; 1.5 −0.5]

Statistics

mean(5; 6; 4; 2; 3; 7) = 4.5

stdev(5; 6; 4; 2; 3; 7) ≈ 1.87

quartile([5 6 4 2 3 7]; 1) = percentile((5; 6; 4; 2; 3; 7); 25) ≈ 2.9166667

normdist(7; 5) ≈ 0.053990967

spearman(column(load(test.csv); 1); column(load(test.csv); 2)) ≈ −0.33737388 (depends on the data in the CSV file)

Time and date

10:31 + 8:30 to time = 19:01

10h 31min + 8h 30min to time = 19:01

now to utc = "2020-07-10T07:50:40Z"

"2020-07-10T07:50CET" to utc+8 = "2020-07-10T14:50:00+08:00"

"2020-05-20" + 523d = addDays(2020-05-20; 523) = "2021-10-25"

today − 5 days = "2020-07-05"

"2020-10-05" − today = days(today; 2020-10-05) = 87 d

timestamp(2020-05-20) = 1 589 925 600

stamptodate(1 589 925 600) = "2020-05-20T00:00:00"

"2020-05-20" to calendars (returns date in Hebrew, Islamic, Persian, Indian, Chinese, Julian, Coptic, and Ethiopian calendars)

Number bases

52 to bin = 0011 0100

52 to bin16 = 0000 0000 0011 0100

52 to oct = 064

52 to hex = 0x34

0x34 = hex(34) = base(34; 16) = 52

523<<2&250 to bin = 0010 1000

52.345 to float ≈ 0100 0010 0101 0001 0110 0001 0100 1000

float(01000010010100010110000101001000) = 1715241/32768 ≈ 52.345001

floatError(52.345) ≈ 1.2207031e-6

52.34 to sexa = 52°20′24″

1978 to roman = MCMLXXVIII

52 to base 32 = 1K

sqrt(32) to base sqrt(2) ≈ 100000

0xD8 to unicode = Ø

code(Ø) to hex = 0xD8

libqalculate's People

Contributors

akaydev-coder avatar alexhenrie avatar bearhoney avatar chengsun avatar coolreader18 avatar daninet avatar emorrp1 avatar ennui93 avatar flaviut avatar hanna-kn avatar idamir avatar ioio85 avatar jcalonso avatar jherkenhoff avatar jlu5 avatar jules-bertholet avatar kanna5 avatar kszug avatar markozajc avatar niclasr avatar norwayfun avatar peterzuger avatar polakrity avatar recolic avatar stephtr avatar thesamesam avatar torstehu avatar triallax avatar tuberry avatar vicsanrope avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libqalculate's Issues

proposal

It could be better if it was possible to have 10 small windows for entry variables easily. Why limit the size of the input data, when I wrote this :

(sqrt(2)/2−sqrt(0.5⋅cos(pi/4+1e−20)/sin(pi/4+1e−20)))⋅(sqrt(2)+2* sqrt(0.5⋅cos(pi/4+1e−20)/sin(pi/4+1e−20))/cos(pi/4+1e−20)⋅sin(pi/4+1e−20))/2/(2⋅(1*1/2+(sqrt(2)/2/cos(pi/4+1e−20))^2/2)/2⋅1e−20)

it is difficult to read. The size of the screen is not use like it could be.

Why don't add the function IN/OUT/CALC like the Fx850P of Casio it is very useful and if it was possible to have more than one input it could be better.

I use a lot of variables, it takes time to add some variables.

my2cents :)

Compute on date/time

Is there a way to compute some operations with date/time (like addition/substraction) ? Like 13h56min12s-1h25min to s ?

Feature request :: new currency :: BTC

Hello, it would be great if Qalculate could make Bitcoin calculations. The BTC/USD and BTC/EUR conversion rates can be retrieved at various places such as Coinbase or Kraken. What do you think?

No scion

No scion in inventory after Tomb of Qualopec.

[RFE] Please add the sinc() function

The sinc(x) function (sometimes abbreviated as si(x) function) is defined as follows:

  • sinc(0) = 1
  • sinc(x) = sin(x)/x ∀ x≠0

This would be a nice function to be added to libqalculate/Qalculate.

I thought adding this code to category "Trigonometry" in data/functions.xml.in:1195 would be enough:

<function>
	<_title>unnormalized sinc function</_title>
	<_names>r:sinc,r:si</_names>
	<expression>if(\x = 0,1,sin(\x))</expression>
</function>

and it works, so I'll add it in a pull request.

Additional info:
This change is backwards-incompatible. I don't know whether you care about that. Currently, running $ qalc "sinc(pi/2)" will interpret this as sin((speed_of_light * (pi / 2)) * radian) and $ qalc "si(pi/2)" will interpret as second * i * (pi / 2).

PS: Thank you for this useful application/library!

Mantissa rounded off in Engineering Mode

When I switch to Mode -> Numerical Display -> Engineering, 1/10 results in 1E-3 (the correct result is of course 1E-1). In Scientific and Normal mode the result is correct.
More examples:
1/10 -> 1E-3 (correct: 100E-3)
1/100 -> 1E-3 (correct: 10E-3)
1/1000 -> 1E-3 (correct)
1/10000 -> 1E-6 (correct: 100E-6)
and so on.
2/100 -> 2E-3 (correct: 20E-3)
2.1/100 -> 21E-3 (correct)
2.0/100 -> 2E-3 (correct: 20E-3)

Precision is on 8 (default)
Decimals are not set (default)

Infinite recursion

Try this:

set approximation approximate
cos(rad)
ans
exact
ans

The application crashed.

libqalculate doesn't gracefully handle mistakenly using a unit of temperature in a hexadecimal expression

People often try to mistakenly input hexadecimal numbers as F2 or 1C (instead of 0xF2 or 0x1C). When they do this, libqualculate produces undefined behavior, which can crash software that uses libqalculate.

You can see this by using KDE KRunner (which uses libqalculate as a backend) and entering either of the following:

  • =(1C)^2
  • =F2

KRunner crashes in response to the undefined output.

This was discovered in https://bugs.kde.org/show_bug.cgi?id=358617

Defining functions in qalc

I'm just starting to use it, and qalc is utterly fantastic.

The documentation seems a bit lacking, though. The documentation for qalculate is complete, but it doesn't always say how to do something in qalc. For example, I found out that a variable can be given a value with the := operator, but the qalculate manual only mentions using the menus.
I haven't figured out how to define a function, though. Is it possible to do that in qalc?

error: use of undeclared identifier 'VERSION'

Hi,

i can not build 0.9.8 version Logs can be find here http://file-store.openmandriva.org/api/v1/file_stores/fd65f91fd4726f4705451b0374ef0d5cb6b35a2f.log?show=true

Compiled with LLVM/clang 3.8.1

In file included from ./DataSet.h:15:
../libqalculate/includes.h:18:17: warning: using directive refers to implicitly-defined namespace 'std'
using namespace std;
^
DataSet.cc:754:61: error: use of undeclared identifier 'VERSION'
xmlNewProp(doc->children, (xmlChar_) "version", (xmlChar_) VERSION);
^
1 warning and 1 error generated.
make[2]: *** [Makefile:529: DataSet.lo] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Entering directory '/builddir/build/BUILD/libqalculate-0.9.8/libqalculate'

Calculator.cc:384:2: warning: ignoring return value of function declared with warn_unused_result attribute [-Wunused-result]
pipe(pipe_wr);
^~~~ ~~~~~~~
Calculator.cc:7589:61: error: use of undeclared identifier 'VERSION'
xmlNewProp(doc->children, (xmlChar_) "version", (xmlChar_) VERSION);
^
Calculator.cc:7667:61: error: use of undeclared identifier 'VERSION'
xmlNewProp(doc->children, (xmlChar_) "version", (xmlChar_) VERSION);
^
Calculator.cc:7835:61: error: use of undeclared identifier 'VERSION'
xmlNewProp(doc->children, (xmlChar_) "version", (xmlChar_) VERSION);
^
Calculator.cc:7996:61: error: use of undeclared identifier 'VERSION'
xmlNewProp(doc->children, (xmlChar_) "version", (xmlChar_) VERSION);
^
Calculator.cc:8200:61: error: use of undeclared identifier 'VERSION'
xmlNewProp(doc->children, (xmlChar_) "version", (xmlChar_) VERSION);
^
4 warnings and 5 errors generated.
make[2]: *** [Makefile:529: Calculator.lo] Error 1

Failure to compile

Hi

I've tried compiling libqalculate just now, with the latest source (30aug '17), but the 'make' sessions fails.

./configure passed ok, so I am not sure what I am missing here.

./configure and make output below

station:~/Downloads/libqalculate-master> ./configure
configure: loading site script /usr/share/site/x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking for library containing strerror... none required
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking dependency style of gcc... (cached) gcc3
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... gcc3
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking dependency style of gcc... (cached) gcc3
checking whether ln -s works... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking whether NLS is requested... yes
checking for intltool-update... /usr/bin/intltool-update
checking for intltool-merge... /usr/bin/intltool-merge
checking for intltool-extract... /usr/bin/intltool-extract
checking for xgettext... /usr/bin/xgettext
checking for msgmerge... /usr/bin/msgmerge
checking for msgfmt... /usr/bin/msgfmt
checking for gmsgfmt... /usr/bin/msgfmt
checking for perl... /usr/bin/perl
checking for perl >= 5.8.1... 5.18.2
checking for XML::Parser... ok
checking build system type... x86_64-suse-linux-gnu
checking host system type... x86_64-suse-linux-gnu
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/x86_64-suse-linux/bin/ld
checking if the linker (/usr/x86_64-suse-linux/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert x86_64-suse-linux-gnu file names to x86_64-suse-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-suse-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/x86_64-suse-linux/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for mt... mt
checking if mt is a manifest tool... no
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking how to run the C++ preprocessor... g++ -E
checking for ld used by g++... /usr/x86_64-suse-linux/bin/ld -m elf_x86_64
checking if the linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) is GNU ld... yes
checking whether the g++ linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC -DPIC
checking if g++ PIC flag -fPIC -DPIC works... yes
checking if g++ static flag -static works... no
checking if g++ supports -c -o file.o... yes
checking if g++ supports -c -o file.o... (cached) yes
checking whether the g++ linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... (cached) GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking for pthread_create in -lpthread... yes
checking mpfr.h usability... yes
checking mpfr.h presence... yes
checking for mpfr.h... yes
checking unordered_map usability... no
checking unordered_map presence... no
checking for unordered_map... no
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for LIBCURL... yes
checking for ICU... yes
checking for LIBXML... yes
checking for ld used by gcc... /usr/x86_64-suse-linux/bin/ld -m elf_x86_64
checking if the linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) is GNU ld... yes
checking for shared library run path origin... done
checking for iconv... yes
checking for working iconv... yes
checking whether to use readline... yes
checking readline/readline.h usability... yes
checking readline/readline.h presence... yes
checking for readline/readline.h... yes
checking readline/history.h usability... yes
checking readline/history.h presence... yes
checking for readline/history.h... yes
checking for readline in -lreadline... yes
  Using -lreadline -lncurses
checking for library containing nanosleep... none required
checking for msgfmt... (cached) /usr/bin/msgfmt
checking for gmsgfmt... (cached) /usr/bin/msgfmt
checking for xgettext... (cached) /usr/bin/xgettext
checking for msgmerge... (cached) /usr/bin/msgmerge
checking for CFPreferencesCopyAppValue... no
checking for CFLocaleCopyCurrent... no
checking for GNU gettext in libc... yes
checking whether to use NLS... yes
checking where the gettext function comes from... libc
checking locale directory... checking for struct lconv.int_p_cs_precedes... yes
checking for struct lconv.int_n_cs_precedes... yes
"/usr/local/share/locale"
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating libqalculate/Makefile
config.status: creating data/Makefile
config.status: creating po/Makefile.in
config.status: creating po-defs/Makefile
config.status: creating docs/Makefile
config.status: creating docs/reference/Makefile
config.status: creating libqalculate.pc
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands
config.status: executing po-directories commands
config.status: creating po/POTFILES
config.status: creating po/Makefile
config.status: executing po/stamp-it commands
claus@Battlestation:~/Downloads/libqalculate-master> make
make  all-recursive
make[1]: Entering directory '/home/claus/Downloads/libqalculate-master'
Making all in libqalculate
make[2]: Entering directory '/home/claus/Downloads/libqalculate-master/libqalculate'
/bin/sh ../libtool  --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I..  -I.. -DPACKAGE_DATA_DIR=\""/usr/local/share"\" -I/usr/include/libxml2      -g -O2 -MT Function.lo -MD -MP -MF .deps/Function.Tpo -c -o Function.lo Function.cc
libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I.. -I.. -DPACKAGE_DATA_DIR=\"/usr/local/share\" -I/usr/include/libxml2 -g -O2 -MT Function.lo -MD -MP -MF .deps/Function.Tpo -c Function.cc  -fPIC -DPIC -o .libs/Function.o
Function.cc: In member function 'virtual std::string IntegerArgument::subprintlong() const':
Function.cc:1735:40: error: 'INT_MIN' was not declared in this scope
    case INTEGER_TYPE_SINT: {str += i2s(INT_MIN); break;}
                                        ^
Function.cc:1737:41: error: 'LONG_MIN' was not declared in this scope
    case INTEGER_TYPE_SLONG: {str += i2s(LONG_MIN); break;}
                                         ^
Function.cc:1758:40: error: 'UINT_MAX' was not declared in this scope
    case INTEGER_TYPE_UINT: {str += i2s(UINT_MAX); break;}
                                        ^
Function.cc:1759:40: error: 'INT_MAX' was not declared in this scope
    case INTEGER_TYPE_SINT: {str += i2s(INT_MAX); break;}
                                        ^
Function.cc:1760:41: error: 'ULONG_MAX' was not declared in this scope
    case INTEGER_TYPE_ULONG: {str += i2s(ULONG_MAX); break;}
                                         ^
Function.cc:1761:41: error: 'LONG_MAX' was not declared in this scope
    case INTEGER_TYPE_SLONG: {str += i2s(LONG_MAX); break;}
                                         ^
Makefile:521: recipe for target 'Function.lo' failed
make[2]: *** [Function.lo] Error 1
make[2]: Leaving directory '/home/claus/Downloads/libqalculate-master/libqalculate'
Makefile:501: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/claus/Downloads/libqalculate-master'
Makefile:409: recipe for target 'all' failed
make: *** [all] Error 2

Kind regards

Get proper exchange rates

Hi,

I'm using the version that came with Kubuntu 17.04: Qalculate! 0.9.9.

When I want to use it for currency conversions, it offers me Euros [€] and only the former currencies, which have now been replaced by euros (e.g. Deutsche Mark). I cannot use any current currencies like British Pounds or US$.

My suspicion is that there is something wrong with fetching the exchange rates from the European Central Bank. It seems to only fetch the frozen exchange rates of those former currencies relative to Euros.

Arithmetic with Celsius

On 0.9.7, 1°C+1°C yielded 2°C (obviously), which converted to Kelvin gave 275.15K. In other words, if you have a temperature of 1 °C and raise it by 1 °C you get 2 °C.
(On the other hand, 1K+1°C yielded 275.15K, which doesn't fit with the description I used.)

On newer versions, however, °C is converted at parse time (which is a bit weird IMO). This results in 1°C+1°C being interpreted as 274.15K+274.15K and thus yielding 548.3K (i.e. 275.15 °C).

I'm aware of the headache that must be dealing with °C and °F programmatically (I've been in that situation before), but I'd suggest fixing this so that it makes more sense. A fix I can think of is to only add the offset to the FIRST occurrence of a temperature, but leave the rest without the extra 273.15K. That way only the first occurrence would be interpreted as an absolute temperature, while the rest would be treated as increments. (This breaks the important concept of commutativity of addition though.)

Additionally, it would be nice if arithmetic done solely with °C yielded a result in °C, not K.


And now if you're curious, this is how I solved this issue back in the day when I had to do a similar thing:

  • Quantities can be interpreted either as absolute or differential. 1°C means either an absolute temperature of 274.15K or an increment (difference) of 1K.
  • Quantities may have an "offset" attribute; for example, a quantity in °C has an equivalence of 1°C=1K and an offset of 273.15K. Quantities internally keep this offset attribute during operations, along with their value.
  • Adding 2 quantities preserves the padding of the first one: it assumes the first quantity is absolute and the second one represents an increment. Thus, 1°C+2°C = 1°C+2K = 3°C = 276.15K
  • Subtracting 2 quantities preserves the padding of the first quantity as well, so it's not suited for calculating a difference between absolute temperatures: it assumes the second quantity is an increment, not an absolute quantity. (Maybe this wasn't a good idea.)
  • Any other operation on quantities (multiplication, division, negation...) discards the offset (it assumes it refers to an increment; for example °C/m means the same as K/m, and cal/°C means the same as cal/K).

I'm not sure if this "extra attribute" thing can be easily implemented with the current libqalculate; probably not. But hopefully making the parser behave like this won't be that hard.

Compilation error when time_t is not long int

Trying to compile version 2.0.0 on FreeBSD 11.0 i386 (clang 3.8.0). In TimestampFunction::calculate(), mstruct.set(time(NULL), 1L, 0L) will fail to compile if time_t is not of type long int. On FreeBSD 32-bit, time_t is int and there is no function to cover this case. I was able to compile it by casting time(NULL) to long int and qalc produced a correct timestamp.

/bin/sh ../libtool  --tag=CXX   --mode=compile c++ -DHAVE_CONFIG_H -I. -I..  -I.. -DPACKAGE_DATA_DIR=\""/usr/local/share"\" -I/usr/local/include   -I/usr/local/include/libxml2   -I/usr/local/include  -DLIBICONV_PLUG -I/usr/local/include -isystem /usr/local/include  -O2 -fno-strict-aliasing -pipe -march=core2 -DLIBICONV_PLUG -fstack-protector -isystem /usr/local/include  -DLIBICONV_PLUG -isystem /usr/local/include -MT BuiltinFunctions.lo -MD -MP -MF .deps/BuiltinFunctions.Tpo -c -o BuiltinFunctions.lo BuiltinFunctions.cc
libtool: compile:  c++ -DHAVE_CONFIG_H -I. -I.. -I.. -DPACKAGE_DATA_DIR=\"/usr/local/share\" -I/usr/local/include -I/usr/local/include/libxml2 -I/usr/local/include -DLIBICONV_PLUG -I/usr/local/include -isystem /usr/local/include -O2 -fno-strict-aliasing -pipe -march=core2 -DLIBICONV_PLUG -fstack-protector -isystem /usr/local/include -DLIBICONV_PLUG -isystem /usr/local/include -MT BuiltinFunctions.lo -MD -MP -MF .deps/BuiltinFunctions.Tpo -c BuiltinFunctions.cc  -fPIC -DPIC -o .libs/BuiltinFunctions.o
BuiltinFunctions.cc:2524:11: error: call to member function 'set' is ambiguous
                mstruct.set(time(NULL), 1L, 0L);
                ~~~~~~~~^~~
../libqalculate/MathStructure.h:251:8: note: candidate function
                void set(int num, int den = 1, int exp10 = 0, bool preserve_precision = false);
                     ^
../libqalculate/MathStructure.h:252:8: note: candidate function
                void set(long int num, long int den, long int exp10 = 0L, bool preserve_precision = false);
                     ^
../libqalculate/MathStructure.h:276:8: note: candidate function not viable: no known conversion from 'time_t' (aka 'int') to 'MathFunction *' for 1st argument
                void set(MathFunction *o, ...);
                     ^
../libqalculate/MathStructure.h:283:8: note: candidate function not viable: no known conversion from 'time_t' (aka 'int') to 'Unit *' for 1st argument
                void set(Unit *u, Prefix *p = NULL, bool preserve_precision = false);
                     ^
../libqalculate/MathStructure.h:237:8: note: candidate function not viable: requires at most 2 arguments, but 3 were provided
                void set(const MathStructure &o, bool merge_precision = false);
                     ^
../libqalculate/MathStructure.h:258:8: note: candidate function not viable: requires at most 2 arguments, but 3 were provided
                void set(string sym, bool preserve_precision = false);
                     ^
../libqalculate/MathStructure.h:264:8: note: candidate function not viable: requires at most 2 arguments, but 3 were provided
                void set(double float_value, bool preserve_precision = false);
                     ^
../libqalculate/MathStructure.h:289:8: note: candidate function not viable: requires at most 2 arguments, but 3 were provided
                void set(Variable *o, bool preserve_precision = false);
                     ^
../libqalculate/MathStructure.h:295:8: note: candidate function not viable: requires at most 2 arguments, but 3 were provided
                void set(const Number &o, bool preserve_precision = false);
                     ^
1 error generated.
gmake[4]: *** [Makefile:532: BuiltinFunctions.lo] Error 1

Inconsistent parsing of single argument functions in RPN syntax expressions

The parsing of an argument expression for a single argument functions is very surprising when using RPN syntax. When there is exactly one object preceding such function, then everything is working as expected. But if there are any calculations involved - everything breaks apart. So, 9 √ returns 3, but 3 3*√ raises error even if stack is not empty. To make things even more confusing, 3 3*.5^ works just fine. That's definitely a limitation of the parser. BTW, I don't seem to find any way to swap top of the stack. Am I missing something?

To put things into context. I'm trying to find a drop-in replacement for dc. I find it's usage of RPN just perfect for my needs, but it has a very limited set of operations. Qalculate! looks very advanced but sometimes it lacks some very basic conveniences of a decent RPN calculator. If only Qalculate! was on par with it's RPN parsing abilities, nobody would ever need to use that old and rusty dc again.

That's not a complain, actually. Qalculate! has the best balance between a desktop calculator and a general algebra system. I just think that Qalculate! is missing a few important pieces that make it not as well known as it really deserves. Thanks for your continuing work on a very useful application.

GTK GUI

I'm trying to install the gui but it requires 0.9.11 version, how it is possible ?

RPN syntax is broken in CLI

Try an example from manual: "5 2 +".

  warning: RPN syntax error. Operator ignored as there where only one stack value.
  52 = 52

The GUI version works, though.

In input base >10 only numbers work

When input base is set to anything greater than 10 variables, functions and units don’t work. Parser thinks everything is a number.
In all the examples bellow output is in base 12.

$ qalc -s "input base 10"   
> 20 pi

  20 * pi ≈ 52.9B954

> log(20)

  log(20, e) ≈ 2.BB4761

> 20 a + 10 ha

  (20 * are) + (10 * hectoare) = 710 a

$ qalc -s "input base 8"    
> 20 pi

  16 * pi ≈ 42.32291

> log(20)

  log(16, e) ≈ 2.93304A

> 20 a + 10 ha

  (16 * are) + (8 * hectoare) = 580 a

$ qalc -s "input base 12"   
> 20 pi

  error: Character 'p' was ignored in the number "20pi" with base 12.
  24 * i = 20i

> log(20)

  error: Character 'l' was ignored in the number "log" with base 12.
  error: Character 'o' was ignored in the number "log" with base 12.
  error: Character 'g' was ignored in the number "log" with base 12.
  0 * 24 = 0

> 20 a + 10 ha

  error: Character 'h' was ignored in the number "10ha" with base 12.
  298 + 154 = 318

Segmentation fault on nonsensical unit conversions/expressions

Certain combinations of nonsensical unit conversions lead to segmentation faults. These expressions all seem to fall into two categories: 1/(t1+x) to t2 and y/(t1+z) to y/t2, where t1 and t2 are different units of time, x is any non-time unit, and y and z are any units.

Here are some examples:

1/(m+s) to h
cd/(ly+ns) to cd/fortnight
1/(dd+s) to h
1/(m+s) to d

However, this pattern doesn't always hold. Here are some examples which follow the patterns I stated above but don't cause segmentation faults:

1/(m+ms) to h
cd/(mm+ms) to cd/d
1/(dd+ms) to h
1/(m+ms) to d

And here are some more expressions I found in the process of writing this issue that also cause segmentation faults:

m/(ly+fs)
cd/(m+ns)
V/(Gh+Gy) to kd

For reference, I am using qalc from version 2.1.0-1 of libqalculate on Arch Linux.

Milli-inch aliases with minute in CLI

The expression .001 in gets normalized to 1 min by default, but the unit string min is interpreted as minute:

> .001in

  0.001 * inch = 1 min

> 1min to s

  1 * minute = 60 s

In particular, the expression it outputs, .001 * inch = 1 min isn't true by its own evaluation:

> .001 * inch == 1 min

  (0.001 * inch) = (1 * minute) = 0

Probably it should spell milli-inch differently in the output (is there a standard way to disambiguate this sort of thing?)

Add BDT currency

Hi,

Can anyone please suggest how to add Bangladeshi Taka (BDT). Something that I want to do is

> 30USD to BDT

Currently it says

warning: Error(s) in unitexpression.
30 * dollar = $30

Please suggest

Proposal for uncertainty propagation feature

The main feature i notice missing in this very useful, expansive tool is the inclusion of uncertainties, which would extend the usefulness of this calculator into territory that it seems very few have tread previously. The inclusion of uncertainty propagation would allow qalculate to be used in a wider range of problems that specifically focus on "real" data where uncertainties are always present. The only other tool i've found that deals with associated uncertainties transparently and correctly is actually a python library which is likely worth looking at for implementation details here: https://pythonhosted.org/uncertainties/

There are several worthwhile syntax choices to choose from, a simple "number+-error" could be used or a new error(value,error,errortype) function or similar could be used to tell qalculate when a value with an error is being considered. Values with errors would then need to be propagated through error propagation rules, and recognize when the same variable is being used to correctly differentiate between the math for dependent and independent errors.

libqalculate.so.6 : No such file or directory

Hello!
I've compiled and installed libcalculate 0.9.10 and qalculate-gtk 0.9.9 from source tarball. In both cases I executed:
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure
make
sudo make install

When I try to run qalc or qalculate-gtk a warning message shows up:
"error while loading shared libraries: libqalculate.so.6: cannot open shared object file: No such file or directory"

I guess some link is missing but I don't know where. libqalculate.so.6 is in "/usr/local/lib/"
My system is linux Mint 18.1 Serena Cinnamon Edition.

Thanks in advance!

Use abstract syntax tree for parser (long term ambitious idea)

After thinking about last issue discussion some more, I came to conclusion that the current parser architecture is too rigid. Maybe it'd be worth considering converting it to use some form of AST and provide an API for consumers to manipulate it in a real time. That way you could abstract all implementation details like a particular strings, keys and their ordering used for different operations. Then the parser would become more clear and modular. It'd also help to make a libcalculate more of a compiler than a UI.

It's an ambitious idea which requires a major rewrite. But I believe that it'd worth it in a long run. Or maybe it's an overkill, it's up for you to decide. Just a thought.

clang and char16_t error on Mac OS X

When building the latest libqalculate (0.9.12) on Mac OS X (10.10.5) via macports, I encountered this error:

libtool: compile:  /usr/bin/clang++ -DHAVE_CONFIG_H -I. -I.. -I.. -DPACKAGE_DATA_DIR=\"/opt/local/share\" -DPACKAGE_LOCALE_DIR=\"/opt/local/share/locale\" -I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include -I/opt/local/include/libxml2 -I/opt/local/include -pipe -Os -stdlib=libc++ -arch x86_64 -O2 -MT Number.lo -MD -MP -MF .deps/Number.Tpo -c Number.cc  -fno-common -DPIC -o .libs/Number.o
DataSet.cc:17:25: error: typedef redefinition with different types ('unsigned short' vs 'char16_t')
typedef __CHAR16_TYPE__ char16_t;
                        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:234:20: note: previous definition is here
typedef __char16_t char16_t;
                   ^
Calculator.cc:27:25: error: typedef redefinition with different types ('unsigned short' vs 'char16_t')
typedef __CHAR16_TYPE__ char16_t;
                        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:234:20: note: previous definition is here
typedef __char16_t char16_t;
^

Deleting:

#if (defined(__clang__) && !defined char16_t)
typedef __CHAR16_TYPE__ char16_t;
#endif

in Calculator.cc and DataSet.cc resolved this for me. Perhaps the if statement is not quite right? My version of clang is

$ clang++ --version
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin14.5.0
Thread model: posix

Compilation error

I am having trouble compiling the latest version of libqalcuate. The ./configure is successful but 'make' results in an error. The output for ./configure and make are shown below. Any help is appreciated.

./configure
configure: loading site script /usr/share/site/x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking for library containing strerror... none required
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking dependency style of gcc... (cached) gcc3
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... gcc3
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking dependency style of gcc... (cached) gcc3
checking whether ln -s works... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking whether NLS is requested... yes
checking for intltool-update... /usr/bin/intltool-update
checking for intltool-merge... /usr/bin/intltool-merge
checking for intltool-extract... /usr/bin/intltool-extract
checking for xgettext... /usr/bin/xgettext
checking for msgmerge... /usr/bin/msgmerge
checking for msgfmt... /usr/bin/msgfmt
checking for gmsgfmt... /usr/bin/msgfmt
checking for perl... /usr/bin/perl
checking for perl >= 5.8.1... 5.18.2
checking for XML::Parser... ok
checking build system type... x86_64-suse-linux-gnu
checking host system type... x86_64-suse-linux-gnu
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/x86_64-suse-linux/bin/ld
checking if the linker (/usr/x86_64-suse-linux/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert x86_64-suse-linux-gnu file names to x86_64-suse-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-suse-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/x86_64-suse-linux/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @file support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for mt... mt
checking if mt is a manifest tool... no
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking how to run the C++ preprocessor... g++ -E
checking for ld used by g++... /usr/x86_64-suse-linux/bin/ld -m elf_x86_64
checking if the linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) is GNU ld... yes
checking whether the g++ linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC -DPIC
checking if g++ PIC flag -fPIC -DPIC works... yes
checking if g++ static flag -static works... no
checking if g++ supports -c -o file.o... yes
checking if g++ supports -c -o file.o... (cached) yes
checking whether the g++ linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... (cached) GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking for pthread_create in -lpthread... yes
checking mpfr.h usability... yes
checking mpfr.h presence... yes
checking for mpfr.h... yes
checking unordered_map usability... no
checking unordered_map presence... no
checking for unordered_map... no
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for LIBCURL... yes
checking for ICU... yes
checking for LIBXML... yes
checking for ld used by gcc... /usr/x86_64-suse-linux/bin/ld -m elf_x86_64
checking if the linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) is GNU ld... yes
checking for shared library run path origin... done
checking for iconv... yes
checking for working iconv... yes
checking whether to use readline... yes
checking readline/readline.h usability... yes
checking readline/readline.h presence... yes
checking for readline/readline.h... yes
checking readline/history.h usability... yes
checking readline/history.h presence... yes
checking for readline/history.h... yes
checking for readline in -lreadline... yes
Using -lreadline -lncurses
checking for library containing nanosleep... none required
checking for msgfmt... (cached) /usr/bin/msgfmt
checking for gmsgfmt... (cached) /usr/bin/msgfmt
checking for xgettext... (cached) /usr/bin/xgettext
checking for msgmerge... (cached) /usr/bin/msgmerge
checking for CFPreferencesCopyAppValue... no
checking for CFLocaleCopyCurrent... no
checking for GNU gettext in libc... yes
checking whether to use NLS... yes
checking where the gettext function comes from... libc
checking locale directory... checking for struct lconv.int_p_cs_precedes... yes
checking for struct lconv.int_n_cs_precedes... yes
"/usr/local/share/locale"
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating libqalculate/Makefile
config.status: creating data/Makefile
config.status: creating po/Makefile.in
config.status: creating po-defs/Makefile
config.status: creating docs/Makefile
config.status: creating docs/reference/Makefile
config.status: creating libqalculate.pc
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands
config.status: executing po-directories commands
config.status: creating po/POTFILES
config.status: creating po/Makefile
config.status: executing po/stamp-it commands
raaj-Laptop:/home/raaj/Desktop/libqalculate-master # make
make all-recursive
make[1]: Entering directory '/home/raaj/Desktop/libqalculate-master'
Making all in libqalculate
make[2]: Entering directory '/home/raaj/Desktop/libqalculate-master/libqalculate'
/bin/sh ../libtool --tag=CXX --mode=link g++ -g -O2 -version-info 12:0:0 -no-undefined -o libqalculate.la -rpath /usr/local/lib64 Function.lo Calculator.lo DataSet.lo Variable.lo ExpressionItem.lo Number.lo MathStructure.lo Prefix.lo util.lo Unit.lo BuiltinFunctions.lo -lcurl -lxml2 -licuuc -licudata -lpthread -lmpfr -lgmp
libtool: link: g++ -fPIC -DPIC -shared -nostdlib /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.8/crtbeginS.o .libs/Function.o .libs/Calculator.o .libs/DataSet.o .libs/Variable.o .libs/ExpressionItem.o .libs/Number.o .libs/MathStructure.o .libs/Prefix.o .libs/util.o .libs/Unit.o .libs/BuiltinFunctions.o -Wl,-rpath -Wl,/usr/lib64 -Wl,-rpath -Wl,/usr/lib64 -lcurl /usr/lib64/libxml2.so -L/lib64 -ldl -lz -llzma -licuuc -licudata -lpthread -lmpfr -lgmp -L/usr/lib64/gcc/x86_64-suse-linux/4.8 -L/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.8/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib64/gcc/x86_64-suse-linux/4.8/crtendS.o /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../lib64/crtn.o -O2 -Wl,-soname -Wl,libqalculate.so.12 -o .libs/libqalculate.so.12.0.0
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../lib64/libgmp.a(lt20-get_str.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../lib64/libgmp.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:486: recipe for target 'libqalculate.la' failed
make[2]: *** [libqalculate.la] Error 1
make[2]: Leaving directory '/home/raaj/Desktop/libqalculate-master/libqalculate'
Makefile:501: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/raaj/Desktop/libqalculate-master'
Makefile:409: recipe for target 'all' failed
make: *** [all] Error 2

Optimal unit conversion may segfault in certain cases

This bug is relevant to optimal unit conversion. The only case I've found to trigger this bug is the input expression 1/u, or 1.0/u with an arbitrary number of zeroes in the fractional part of 1. Using any other number as the numerator, like 2, 0, or even -1, does not trigger this bug. Replacing the atomic mass unit u with its unit representation gram/mole and using 1/(gram/mole) yields the correct result 1 mole/gram.

To reproduce, enable optimal unit conversion and enter 1/u as input within any libqalculate-based application (qalc, qalculate-gtk, krunner, qalculate plasmoid).
Tested with libqalculate versions 0.9.11 and 0.9.9.

Test case, running qalc under valgrind:

$ valgrind qalc
==23361== Memcheck, a memory error detector
==23361== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==23361== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==23361== Command: qalc
==23361== 
> set autoconversion base
> u

  atomic_mass_unit = 1(g / mol)

> 1/u

  1 / atomic_mass_unit = 1(mol / g)

> 2/u

  2 / atomic_mass_unit = 2(mol / g)

> 1/(g/mol)

  1 / (gram / mole) = 1(mol / g)

> set autoconversion optimal

  1 / (gram / mole) = 1(mol / g)

> 2/u

  2 / atomic_mass_unit = 2(mol / g)

> 1/u
==23361== Thread 3:
==23361== Invalid read of size 8
==23361==    at 0x55AEDBD: Calculator::getBestUnit(Unit*, bool) (Calculator.cc:2742)
==23361==    by 0x55AEF8D: Calculator::getBestUnit(Unit*, bool) (Calculator.cc:2895)
==23361==    by 0x55BE528: Calculator::convertToBestUnit(MathStructure const&, EvaluationOptions const&) (Calculator.cc:2997)
==23361==    by 0x56034F8: Calculator::calculate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, EvaluationOptions const&, MathStructure*, MathStructure*, bool) (Calculator.cc:2328)
==23361==    by 0x5603CC8: calculate_proc(void*) (Calculator.cc:221)
==23361==    by 0x5FAD453: start_thread (in /usr/lib/libpthread-2.24.so)
==23361==    by 0x6EDB7DE: clone (in /usr/lib/libc-2.24.so)
==23361==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==23361== 
==23361== 
==23361== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==23361==  Access not within mapped region at address 0x0
==23361==    at 0x55AEDBD: Calculator::getBestUnit(Unit*, bool) (Calculator.cc:2742)
==23361==    by 0x55AEF8D: Calculator::getBestUnit(Unit*, bool) (Calculator.cc:2895)
==23361==    by 0x55BE528: Calculator::convertToBestUnit(MathStructure const&, EvaluationOptions const&) (Calculator.cc:2997)
==23361==    by 0x56034F8: Calculator::calculate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, Evaucture*, MathStructure*, bool) (Calculator.cc:2328)
==23361==    by 0x5603CC8: calculate_proc(void*) (Calculator.cc:221)
==23361==    by 0x5FAD453: start_thread (in /usr/lib/libpthread-2.24.so)
==23361==    by 0x6EDB7DE: clone (in /usr/lib/libc-2.24.so)
==23361==  If you believe this happened as a result of a stack
==23361==  overflow in your program's main thread (unlikely but
==23361==  possible), you can try to increase the size of the
==23361==  main thread stack using the --main-stacksize= flag.
==23361==  The main thread stack size used in this run was 8388608.
==23361== 
==23361== HEAP SUMMARY:
==23361==     in use at exit: 930,443 bytes in 5,830 blocks
==23361==   total heap usage: 160,603 allocs, 154,773 frees, 11,549,528 bytes allocated
==23361== 
==23361== LEAK SUMMARY:
==23361==    definitely lost: 72,602 bytes in 379 blocks
==23361==    indirectly lost: 0 bytes in 0 blocks
==23361==      possibly lost: 576 bytes in 2 blocks
==23361==    still reachable: 857,265 bytes in 5,449 blocks
==23361==         suppressed: 0 bytes in 0 blocks
==23361== Rerun with --leak-check=full to see details of leaked memory
==23361== 
==23361== For counts of detected and suppressed errors, rerun with: -v
==23361== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Killed

intltool and gettext

With intltool as part of the build, autoreconf needs to be rerun in a macports environment so that the correct perl is used. Now with the addition of gettext in 2.x, I get this error:
config.status: error: po/Makefile.in.in was not created by intltoolize.
It seems that intltool and gettext cause problems when used together:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=724555

Can you fix or suggest a workaround? Thanks.

Discrepancies between try exact and approximate

I'm not sure if this was intended or an oversight. The display of a result in try exact and approximate mode is different for calculations with approximate numbers. Try e.g.:

set approximation approximate
pi/2
save v
cos(v*rad)
approximate

Aborting long computations can crash

Try e.g. to factor Mersenne prime 2^61-1 and then press enter to abort it. The result is a crash with this message: terminate called without an active exception.

Ignore comma in numbers

qalculate-gtk has this option in preferences. How to enable it in command-line qalc? Is there any command line switch for it? If there is, can we get this listed in qalc --help? If not, please treat it as a feature request for qalc.

qalc segfaults upon exit

qalc is segfaulting upon exit if no commands are issued other than 'help'. If qalc is started and a calculation is performed, it seems to exit normally. Backtrace is from version 1.0.0.

Platform:
FreeBSD 11.0 i386 (clang 3.8.0)

Steps to reproduce:

  1. start qalc
  2. enter help command (optional)
  3. enter exit command
Reading symbols from qalc...done.
(gdb) run
Starting program: /usr/local/bin/qalc 
[New LWP 100449 of process 9739]
> exit

Thread 2 received signal SIGSEGV, Segmentation fault.
[Switching to LWP 100449 of process 9739]
MathStructure::type (this=0x0) at MathStructure.cc:9923
9923            return m_type;
(gdb) bt
#0  MathStructure::type (this=0x0) at MathStructure.cc:9923
#1  0x286fde9c in MathStructure::set (this=0xbbbfde88, o=..., merge_precision=false) at MathStructure.cc:273
#2  0x286fdd5b in MathStructure::MathStructure (this=0xbbbfde88, o=...) at MathStructure.cc:206
#3  0x08112a19 in ViewThread::run (this=0x294e9ce0) at qalc.cc:2828
#4  0x28854c3a in Thread::doRun (data=0x294e9ce0) at util.cc:949
#5  0x282caf2c in ?? () from /lib/libthr.so.3
#6  0x00000000 in ?? ()

Missing functions for manupulating stack in RPN mode

Every RPN calculator should have at least swap and duplicate top operations. Some provide rotate stack as well. Without such functions it's very difficult to arrange ordinary calculations without resorting to memory variables. But these are not part of a stack machine.

Deadlock after calling Calculator::calculate()

The following simple code causes a deadlock for me when using libqalculate v2.0.0.

#include <libqalculate/qalculate.h>

int main() {
  Calculator* pcalc = new Calculator();
  MathStructure result;
  pcalc->calculate(&result, "1+1", 2000);
  delete pcalc;
  return 0;
}

Here is a backtrace showing the issue:

(gdb) thread apply all bt

Thread 2 (Thread 0x7fffee1d5700 (LWP 20434)):
#0  0x00007ffff582c20d in read () at ../sysdeps/unix/syscall-template.S:84
#1  0x00007ffff57bd889 in _IO_new_file_underflow (fp=0x616000000380) at fileops.c:600
#2  0x00007ffff57bc6f8 in __GI__IO_file_xsgetn (fp=0x616000000380, data=<optimized out>, n=1) at fileops.c:1422
#3  0x00007ffff57aebe1 in __GI__IO_fread (buf=<optimized out>, size=1, count=1, fp=0x616000000380) at iofread.c:38
#4  0x00007ffff68a7628 in Thread::read<bool> (this=0x6080000016a0, data=0x7fffee1d49a0) at ../libqalculate/util.h:151
#5  0x00007ffff67bceb0 in CalculateThread::run (this=0x6080000016a0) at Calculator.cc:240
#6  0x00007ffff6aa083f in Thread::doRun (data=0x6080000016a0) at util.cc:783
#7  0x00007ffff6427617 in start_thread (arg=0x7fffee1d5700) at pthread_create.c:456
#8  0x00007ffff583bb8f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97

Thread 1 (Thread 0x7ffff7f88cc0 (LWP 20356)):
#0  __lll_lock_wait_private () at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
#1  0x00007ffff57bdeb8 in __GI__IO_un_link (fp=0x616000000380) at genops.c:67
#2  0x00007ffff57be0b2 in __GI__IO_un_link (fp=<optimized out>) at genops.c:92
#3  0x00007ffff57ad98d in _IO_new_fclose (fp=0x616000000380) at iofclose.c:54
#4  0x00007ffff6efdf81 in fclose () from /usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/libasan.so.4
#5  0x00007ffff6aa0632 in Thread::~Thread (this=0x6080000016a0, __in_chrg=<optimized out>) at util.cc:763
#6  0x00007ffff68de0c7 in CalculateThread::~CalculateThread (this=0x6080000016a0, __in_chrg=<optimized out>) at Calculator.cc:214
#7  0x00007ffff68de0e2 in CalculateThread::~CalculateThread (this=0x6080000016a0, __in_chrg=<optimized out>) at Calculator.cc:214
#8  0x00007ffff67c4a10 in Calculator::~Calculator (this=0x624000000100, __in_chrg=<optimized out>) at Calculator.cc:491
#9  0x00007ffff67c4e02 in Calculator::~Calculator (this=0x624000000100, __in_chrg=<optimized out>) at Calculator.cc:496
#10 0x000000000040170c in main ()

Basically the calculator thread is being shut down without being notified about this.
So it is still stuck in Thread::read<bool>() and will never return making the destruction of the Calculator object impossible.

I don't fully understand this threading/signaling concept but I guess you need something
to unblock this read here in CalculateThread::run():

bool b_parse = true;
if(!read<bool>(&b_parse)) break;

Bug parsing simple expression ("-" is not a valid variable/function/unit)

I came across a weird bug while using Qalculate! GTK. Entering the formula

(x-"y")^2 + 2*x*1

yields "2x" because the (x-"y") expression is interpreted as (x * (0 * y)). Note that copy/pasting it does not work, as unicode characters need to be used, more on that on following comments. You can use the expression below for pasting:

(x−"y")^2 + 2⋅x⋅1

Aliases for currencies

It is a bit cumbersome to convert to e.g. czech koruna. Sign isn't supported and code is accepted only as upper case which is not so comfortable to write. (All those $2 outputs are incorrect.)

qalc -t 2$ to czk
$2

qalc -t 2$ to CZK
CZK 48.959957

qalc -t 2$ to Kč
$2

qalc -t 2$ to Kc
$2

qalc -t 2$ to kc
$2

Also full name seems to be missing:

qalc -t 2 DOLLAR to EURO
EUR 1.8119224

qalc -t 2$ to CZECH KORUNA
7.751938((u$*A*C*EC*H*K*N*R*s) / (MA^2 * K*g*m^3))

qalc -t 2$ to CZECHKORUNA
7.751938((u$*A*C*EC*H*K*N*R*s) / (MA^2 * K*g*m^3))

qalc -t 2$ to CZECH_KORUNA
7.751938((u$*A*C*EC*H*K*N*R*s) / (MA^2 * K*g*m^3))

qalc -t 2$ to CZECH KORUNY
7.751938((n$*C*EC*H*K*N*R*s) / (GA*K*g*m^3))

qalc -t 2$ to CZECHKORUNY
7.751938((n$*C*EC*H*K*N*R*s) / (GA*K*g*m^3))

qalc -t 2$ to CZECH_KORUNY
7.751938((n$*C*EC*H*K*N*R*s) / (GA*K*g*m^3))

I noticed that some currencies are way better with tons of synonyms and support of sign. E.g. dollar or euro:

qalc -t 2 dollars to euros
EUR 1.8119224

qalc -t 2$ to €
EUR 1.8119224

It would be nice to have other currencies supported as well (not just CZK).

I think full name is not that important, but a currency sign is nice-to-have and a currency code in lower case is IMO a must.

Trashed parser response

Try

set unknowns off
xyz
set base 10
set angle unit rad

The response from a previous error is repeated every time.

parsing of "1 W Ohm /K/K"

Why should 1 W Ohm /K/K be different from 1 W Ohm /K /K? What's wanted in any case is 1 watt ohm kelvin^-2. The first form, however, gives 1 W Ohm and the two kelvins cancel.

Build failure with clang++/libc++ on Linux

When building with clang++/libc++ on Linux, I get the following error:

In file included from Function.cc:14:
In file included from ./Function.h:15:
In file included from ../libqalculate/ExpressionItem.h:15:
In file included from ../libqalculate/includes.h:47:
/usr/bin/../include/c++/v1/ext/hash_map:213:5: warning: Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map> [-W#warnings]
#   warning Use of the header <ext/hash_map> is deprecated.  Migrate to <unordered_map>

In file included from Function.cc:14:
In file included from ./Function.h:15:
In file included from ../libqalculate/ExpressionItem.h:15:
../libqalculate/includes.h:54:4: error: invalid preprocessing directive
#               #define unordered_map Sgi::hash_map

In file included from Function.cc:14:
./Function.h:74:2: error: unknown type name 'unordered_map'
        unordered_map<size_t, Argument*> argdefs;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.