👨‍💻 about me home CV/Resume 🖊️ Contact Github LinkedIn I’m a Haskeller 📝 Blog Freedom, privacy, tutorials… 🏆 Best of panda upp Haskell abp pp hCalc bl lapp todo pwd TPG Nextcloud Git BitTorrent

💣 Kick GAFAMs out (✔️ ǝlƃooפ, ✔️ ʞooqǝɔɐℲ, ✔️ uozɐɯ∀): Stop giving our soul and money to evils, be free and respectful!
📰 Friday 2. April 2021: upp is a panda companion. It’s a Lua-scriptable lightweight text preprocessor.
🆕 since December 2020: Playing with the actor model in an embedded multicore context. C imperative components become C stream pure functions with no side effect ➡️ C low level programming with high level pure functional programming properties 🏆
📰 Saturday 30. January 2021: Playing with Pandoc Lua filters in Lua. panda is a lightweight alternative to abp providing a consistent set of Pandoc filters (text substitution, file inclusion, diagrams, scripts, …).
🆕 Sunday 24. May 2020: Working at EasyMile for more than 5 years. Critical real-time software in C, simulation and monitoring in Haskell ➡️ perfect combo! It’s efficient and funny ;-)
🚌 And we are recruiting! Contact if you are interested in Haskell or embedded softwares (or both).

Calculadoira - A programmer’s Calculator using Bonaluna

Christophe Delord

28 mai 2020


Calculadoira is inspired by Calc.

Calculadoira is based on Bonaluna instead of Python. It’s lighter and faster to load.

This software is released under the GPL license.

|     C A L C U L A D O I R A      v. 3.1.0 | cdelord.fr/calculadoira |
| Modes:                          | Numbers:                          |
|     hex oct bin float str reset |     binary: 0b...                 |
|     hex8/16/32/64 ...           |     octal : 0o...                 |
|---------------------------------|     hexa  : 0x...                 |
| Variables and functions:        |     float : 1.2e-3                |
|     variable = expression       |     sep "_", sep " ", sep ""      |
|     function(x, y) = expression | Chars     : "abcd" or 'abcd'      |
| Multiple statements:            |             "<abcd" or ">abcd"    |
|     expr1, ..., exprn           | Booleans  : true or false         |
| Builtin functions:              | Operators:                        |
|     see help                    |     or xor and not                |
|---------------------------------|     < <= > >= == !=               |
| Commands: ? help license bye    |     cond?expr:expr                |
|           edit ascii            |     + - * / % ** | ^ & >> << ~    |


Command line usage

Calculadoira accepts command line parameters:

loads a file and evaluates its content. This may be used to import some user libraries before entering an interactive session.

calculadoira.ini is automatically loaded if it exists.

The edit command edits the first loaded file. Changes are automatically reloaded, it’s not necessary to restart Calculadoira.


Constants                   Value
=========================== ===============================================

nan, NaN                    Not a Number
inf, Inf                    Infinite
pi                          3.1415926535898
e                           2.718281828459

Operators / functions       Description
=========================== ===============================================

+x, -x
x + y, x - y                sum, difference
x * y, x / y, x % y         product, division
x // y, x % y               integral division, modulo
x ** y                      x to the power y

~x                          bitwise not
x | y, x ^ y, x & y         bitwise or, xor, and
x << n, x >> n              x left or right shifted by n bits

not x                       boolean not
x or y, x xor y, x and y    boolean or, xor, and
x < y, x <= y               comparisons
x > y, x >= y
x == y, x != y, x ~= y

x!                          factorial of x
|x|                         absolute value of x

int(x)                      x converted to int
float(x)                    x converted to float
rat(x)                      x converted to rat

abs(x)                      absolute value of x
ceil(x)                     smallest integer larger than or equal to x
floor(x)                    largest integer smaller than or equal to x
round(x)                    round to the nearest integer
trunc(x)                    tround toward zero
mantissa(x)                 m such that x = m2e, |m| is in [0.5, 1[
exponent(x)                 e such that x = m2e, e is an integer
int(x)                      integral part of x
fract(x)                    fractional part of x
fmod(x, y)                  remainder of the division of x by y
ldexp(m, e)                 m*2**e (e should be an integer)
pow(x, y)                   x to the power y
min(...), max(...)          minimum / maximum value among its arguments

sqr(x)                      square of x (x**2)
sqrt(x)                     square root of x (x**0.5)
cbrt(x)                     cubic root of x (x**(1/3))

cos(x), acos(x), cosh(x)    trigonometric functions
sin(x), asin(x), sinh(x)
tan(x), atan(x), tanh(x)
atan(y, x), atan2(y, x)     arc tangent of y/x (in radians)
deg(x)                      angle x (given in radians) in degrees
rad(x)                      angle x (given in degrees) in radians

exp(x)                      e**x
exp2(x)                     2**x
expm1(x)                    e**x - 1
log(x), ln(x)               logarithm of x in base e
log10(x), log2(x)           logarithm of x in base 10, 2
log1p(x)                    log(1 + x)
logb(x)                     log2(|x|)
log(x, b)                   logarithm of x in base b

random()                    random number in [0, 1[
random(m)                   random integer in [1, m]
random(m, n)                random integer in [m, n]
randomseed(x)               x as the "seed" for the pseudo-random generator

float2ieee(x)               IEEE 754 representation of x (32 bits)
ieee2float(n)               32 bit float value of the IEEE 754 integer n
double2ieee(x)              IEEE 754 representation of x (64 bits)
ieee2double(n)              64 bit float value of the IEEE 754 integer n

erf(x)                      error function
erfc(x)                     complementary error function
gamma(x)                    gamma function
lgamma(x)                   log-gamma function

isfinite(x)                 true if x is finite
isinf(x)                    true if x is infinite
isnan(x)                    true if x is not a number

copysign(x, y)              sign(y) * |x|
fdim(x, y)                  x - y if x>y, 0 otherwise
hypot(x, y)                 sqrt(x**2 + y**2)
nextafter(x, y)             next float after x in the directory of y
remainder(x, y)             remainder of x/y
scalbn(x, n)                x * 2**n

fma(x, y, z)                x*y + z

Display modes

dec, hex, oct, bin and str commands change the display mode.
When enabled, the integer result is displayed in
hexadecimal, octal, binary and/or as a string.
float mode shows float values and their IEEE encoding.
str mode show the ASCII representation of 1 upto 4 chars.

dec, hex, oct, bin can have suffixes giving the number of bits
to be displayed (e.g. hex16 shows 16 bit results). Valid suffixes
are 8, 16, 32, 64 and 128.

float can have suffixes giving the size of floats (32 or 64).

The reset command reset the display mode.

The sep command set the digit separator. valid separators are:
- sep "": no separator
- sep " ": digits separated with space
- sep "_": digits separated with an underscore

Note: the space separator cannot be used to enter numbers.


A block is made of several expressions separated by `,` or ` `.
The value of the block is the value of the last expression.

e.g. x=1, y=2, x+y defines x=1, y=2 and returns 3

Definitions made in functions are local.

e.g. f(x) = (y=1, x+y) defines a function f that
returns x+1. y is local to f.

Local definitions can be functions.

e.g. fact(n) = (f(n,p)=(n==1)?p:f(n-1,n*p), f(n,1))

Operator precedence

From highest to lowest precedence:

Operator family             Syntax
=========================== =================
Precedence overloading      (...)
Absolute value              |x|
Function evaluation         f(...)
Factorial                   x!
Exponentiation              x**y
Unary operators             +x, -y, ~z
Multiplicative operators    * / % & << >>
Additive operators          + - | ^
Relational operators        < <= > >= == !=
Logical not                 not x
Logical and                 and
Logical or                  or xor
Ternary operator            x ? y : z
Assignement                 x = y
Blocks                      expr1, ..., exprn

Other commands              Description
=========================== ===========================

bye                         quit
edit                        edit the configuration file
ascii                       print an ASCII table


Calculadoira: http://cdelord.fr/calculadoira
BonaLuna    : http://cdelord.fr/bl

"Calculadoira" means "Calculator" in Occitan.

: license
Copyright (C) 2011 - 2020 Christophe Delord

Calculadoira is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Calculadoira is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Calculadoira.  If not, see <http://www.gnu.org/licenses/>.



: reverse(x) = (d=int(x/10), u=x%10, u*10+d)
: answer = reverse(24)
=	42

: fact(n) = n>1 ? n*fact(n-1) : 1
: fact(answer)
=	1405006117752879898543142606244511569936384000000000

: answer * 1000
=	42000

ASCII codes

: '42'
=	13362
hex	0x3432
str	"42"

: lower(ascii) = ascii | ' ', lower('A')
=	97
hex	0x61
str	"a"

: upper(ascii) = ascii & ~' ', upper('a')
=	65
hex	0x41
str	"A"

IEEE floats

: float
: 1.5
=	1.5
IEEE	1.5 <=> 0x3FC00000

: 0x3fc00000 | 1<<31
=	3217031168
hex32	0xBFC00000
IEEE	-1.5 <=> 0xBFC00000

: pi
=	3.1415926535898
IEEE	3.1415927410126 <=> 0x40490FDB

: float64
: pi
=	3.1415926535898
IEEE	3.1415926535898 <=> 0x400921FB54442D18

Operating Systems support


Calculadoira is intended to run in a terminal. It works everywhere Bonaluna (i.e. Lua) runs.

Just execute calculadoira.lua (bl shall be in the PATH).

Calculadoria license for Windows users

Calculadoira is free (as in freedom) but Windows users have to buy the professional edition to get rid of the trial screen and to support Calculadoira development.

Just pay with PayPal (see below) to get the professional edition.

Prices are:

But Linux users can support Calculadoira too ;-)

Number of users

You can try Calculadoira for Windows for free. calculadoira-demo.exe contains calculadoira.lua, the default configuration file and a Bonaluna interpretor.

If you find it useful, please consider buying the professional edition to support its development.