Contact me

Twitter  🙋  LinkedIn

Monday 16. December 2019: Working at EasyMile for nearly 3 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).

Sunday 15. December 2019: Playing with Pandoc filters in Haskell. abp should make pp obsolete.

Haskell Haskell Handy Calc abp pp Python TPG Vim todo pwd

16 août 2015

# Introduction

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.0.9 | cdsoft.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:

`filename`
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.

# Help

``````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.

Blocks
======

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

Credits
=======

Calculadoira: http://www.cdsoft.fr/calculadoira
BonaLuna    : http://www.cdsoft.fr/bl

"Calculadoira" means "Calculator" in Occitan.

: license
Calculadoira
Copyright (C) 2011 - 2015 Christophe Delord
http://www.cdsoft.fr/calculadoira

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
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
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/>.
``````

# Examples

## Functions

``````: 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

## GNU/Linux

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:

• 10 € for a single user individual license
• 20 € for a single user professional license
• 190 € for a 10 user professional license
• 1800 € for a 100 user professional license

But Linux users can support Calculadoira too ;-)

 Number of users Single user - €10,00 EUR Single professional user - €20,00 EUR 10 professional users - €190,00 EUR 100 professional users - €1 800,00 EUR

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.