toolbox

Check-in [1d0bf615b7]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:calc: improve man page documentation
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1d0bf615b757c59047a47b6337692093892d280c9b4a251e8f07d5ff8ff58b27
User & Date: jef 2019-05-06 12:10:32
Context
2019-05-06
13:30
calc: fix typo in documentation check-in: 5cd253ea48 user: jef tags: trunk
12:10
calc: improve man page documentation check-in: 1d0bf615b7 user: jef tags: trunk
2019-05-03
07:42
http-code: add flag to enable redirects check-in: 564880f6c2 user: jef tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to doc/calc.md.

11
12
13
14
15
16
17
18



































































































































































































































































































































































































































































































































































































19
20
21
<
*commands*

## DESCRIPTION

**calc**
is a RPN calculator in the spirit of the HP calculators.




































































































































































































































































































































































































































































































































































































## AUTHOR

Gerome Fournier <[jef@foutaise.org](mailto:jef@foutaise.org)>.








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
<
*commands*

## DESCRIPTION

**calc**
is a RPN calculator in the spirit of the HP calculators.

## CALC SETTINGS

### dsp

Control the number of stack entries to display (4 by default).

	4:
	3:
	2:
	1:                 1.00
	> 2 dsp
	
	2:
	1:                 1.00
	>

### prec

Specify float precision (2 by default).

	1:                 3.14
	> 4 prec
	
	1:               3.1416
	>

### rad

Switch to radius mode.

### deg

Switch to degree mode.

## STACK MANAGEMENT

### clear

Clear the stack.

### dropn

Remove the n topmost elements of the stack.

	4:                 2.00
	3:                33.00
	2:                44.00
	1:                55.00
	> 3 dropn
	
	4:
	3:
	2:
	1:                 2.00
	>

### drop2

Shortcut for 2 dropn.

### drop

Shortcut for 1 dropn.

### dupn

Duplicate the n topmost elements of the stack.

	4:
	3:
	2:                 3.14
	1:                34.00
	> 2 dupn
	
	4:                 3.14
	3:                34.00
	2:                 3.14
	1:                34.00
	>

### dup2

Shortcut for 2 dupn.

### dup

Shortcut for 1 dupn.

### pick

Pick an element in the stack and copy it at the top of the stack.

	4:
	3:               123.00
	2:                33.00
	1:                44.00
	> 3 pick
	
	4:               123.00
	3:                33.00
	2:                44.00
	1:               123.00
	>

### over

Shortcut for 2 pick.

### roll

Pick an element in the stack and move it at the top of the stack.

	4:
	3:               123.00
	2:                33.00
	1:                44.00
	> 3 roll
	
	4:
	3:                33.00
	2:                44.00
	1:               123.00
	>

### swap

Shortcut for 2 roll.

### rot

Shortcut for 3 roll.

### rolld

Pick the topmost element and move it downward the stack.

	4:                 1.00
	3:                 2.00
	2:                 3.00
	1:                 4.00
	> 3 rolld
	
	4:                 1.00
	3:                 4.00
	2:                 2.00
	1:                 3.00
	>

### depth

Push the size of the stack on the stack.

## ARITHMETIC OPERATORS

### add, +

Add two topmost elements of the stack.

### sub, -

Substract two topmost elements of the stack.

### mul, \*

Multiply two topmost elements of the stack.

### div, /

Divide two topmost elements of the stack.

### modulo, %

Modulo of two topmost elements of the stack.

### pow

Exponentiation operator of two topmost elements of the stack.

### sq

Shortcut for 2 pow (square value of topmost element).

### sqrt

Shortcut for .5 pow (square root value of topmost element).

### neg

Negate topmost element of the stack.

### abs

Replace topmost element of the stack by its absolute value.

### ceil

Replace topmost element of the stack by its ceiling value.

### floor

Replace topmost element of the stack by its floor value.

### round

Replace topmost element of the stack by its round value.

### sum

Sum every element of the stack.

### avg

Compute average value of the stack.

## COMPARATORS

### equal

Test if second element equals first one.

### le

Test if second element is less or equal compared to first one.

### lt

Test if second element is less than first one.

### ge

Test if second element is greater or equal compared to first one.

### gt

Test if second element is greater than first one.

## BASE NUMBERS

**calc**
accepts numbers in 'base mode' format, using the following syntax:

\#...b

> binary base number (example #01b)

\#...o

> octal base number (example #12o)

\#...d

> decimal base number (example #23d)

\#...h

> hexadecimal base number (example #ea1h)

Base numbers are displayed in decimal base by default.
See commands
*bin*,
*oct*,
*dec*,
*hex*
to change the default base number display mode.

### base

Turn a float number into a base number.

### float

Turn a base number into a float number.

### bin

Display base numbers in base 2.

### oct

Display base numbers in base 8.

### dec

Display base numbers in base 10.

### hex

Display base numbers in base 16.

## BITWISE OPERATORS

### blshift

Binary left shift operator.

	4:
	3:
	2:
	1:                 1.00
	> 2 blshift
	
	4:
	3:
	2:
	1:                 4.00
	>

### brshift

Binary right shift operator.

### band

Binary and between two topmost elements.

### bor

Binary or between two topmost elements.

### bxor

Binary xor between two topmost elements.

## CONSTANTS

### pi

The Pi constant.

### e

Natural logarithm.

## TRIGONOMETRY

### cos

Cosinus.

### sin

Sinus.

### tan

Tangent.

### acos

Arc-cosinus.

### asin

Arc-sinus.

### atan

Arc-tangent.

### cosh

Hyperbolic-cosinus.

### sinh

Hyperbolic-sinus.

### tanh

Hyperbolic-tangent.

## LABELS

**calc**
supports the notion of labels, where values can be stored to / retrieved
from. A valid label name is made of alphabetic characters and underscore
character.

A label can be entered as is. If a value is already assigned to a label,
the stored value is pushed on the stack. Otherwise, the label name is put
on the stack. To put a label on the stack without evaluation, enter it in
single quotes.

### mem

Dump a list of labels and their associated value.

### sto

Store a value into a label:

	4:
	3:
	2:
	1:
	> 2 'two' sto
	
	4:
	3:
	2:
	1:
	> mem
	
	two: 2.00
	
	4:
	3:
	2:
	1:
	> two
	
	4:
	3:
	2:
	1:                 2.00
	>

### sto+

Increment value stored in a label with the topmost value of the stack.

	4:
	3:
	2:
	1:                 5.00
	> 'two' sto+
	
	4:
	3:
	2:
	1:
	> two
	
	4:
	3:
	2:
	1:                 7.00
	>

### rcl

Recall a value stored in a label.

	4:
	3:
	2:
	1:
	> 'two' rcl
	
	4:
	3:
	2:
	1:                 7.00
	>

### purge

Unassign value stored in a label.

	4:
	3:
	2:
	1:
	> 'two' purge

## PROGRAMS

### <<...>>

Sequences of commands can be specified between double angle brackets:

	4:
	3:
	2:
	1:
	> <<3 4 5 6>>
	
	4:
	3:
	2:
	1: <<3.00 4.00 5.00 6.00>
	>

### eval

A program on top of the stack can be evaluted with the eval command:

	4:
	3:
	2:
	1: <<3.00 4.00 5.00 6.00>
	> eval
	
	4:                 3.00
	3:                 4.00
	2:                 5.00
	1:                 6.00
	>

## CONTROL FLOW

### ift

If-then conditionnal. Expect a program as a first argument, and an int value
as a second argument. program is evaluated if float value is not zero.

	4:
	3:
	2: 1
	1: <<3.00 4.00 add>>
	> ift
	
	4:
	3:
	2:
	1:                 7.00
	>

### ifte

If-then-else conditionnal. Expect programs on first and second arguments,
and an int value as a third argument. Evaluate first program if third
argument is not zero, evaluate second program otherwise.

	4:
	3: 0
	2: <<1.00 1.00 add>>
	1: <<2.00 2.00 mul>>
	> ifte
	
	4:
	3:
	2:
	1:                 2.00
	>

### whileop

While loop operator. Expect programs on first and second arguments.
Evaluate first program as long a second program evaluate to a float
value that is not zero.

## COMMENTS

The '@' character mark the beginning of a comment. Following characters
until EOL are discarded.

	4:
	3:
	2:
	1:
	> @ this is a comment

## RCFILE

On startup,
**calc**
parse the $HOME/.config/calc/calcrc if it exists. You can store there
your custom commands. For example, this rc file defines a rgb command
by storing a program into the 'rgb' label:

	$ cat ~/.config/calc/calcrc
	@ 'rgb' command to convert an hexadecimal color value into RGB format
	<<dup 16 brshift #ffh band swap dup 8 brshift #ffh band swap #ffh band>> 'rgb' sto
	
	$ calc
	
	4:
	3:
	2:
	1:
	> #63c6a5h rgb
	
	4:
	3:                 #99d
	2:                #198d
	1:                #165d
	>

## AUTHOR

Gerome Fournier &lt;[jef@foutaise.org](mailto:jef@foutaise.org)&gt;.

Changes to src/calc/calc.1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14




















































































































































































































































































































































































































































15
16
.Dd January 2019
.Dt calc 1
.Os
.Sh Name
.Nm calc
.Nd RPN calculator
.Sh SYNOPSIS
.Nm
.Nm
<
.Ar commands
.Sh DESCRIPTION
.Nm
is a RPN calculator in the spirit of the HP calculators.




















































































































































































































































































































































































































































.Sh AUTHOR
.An Gerome Fournier Aq Mt jef@foutaise.org .
|













>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
.Dd May 2019
.Dt calc 1
.Os
.Sh Name
.Nm calc
.Nd RPN calculator
.Sh SYNOPSIS
.Nm
.Nm
<
.Ar commands
.Sh DESCRIPTION
.Nm
is a RPN calculator in the spirit of the HP calculators.
.Sh CALC SETTINGS
.Ss dsp
Control the number of stack entries to display (4 by default).
.Bd -literal
4:
3:
2:
1:                 1.00
> 2 dsp

2:
1:                 1.00
>
.Ed
.Ss prec
Specify float precision (2 by default).
.Bd -literal
1:                 3.14
> 4 prec

1:               3.1416
>
.Ed
.Ss rad
Switch to radius mode.
.Ss deg
Switch to degree mode.
.Sh STACK MANAGEMENT
.Ss clear
Clear the stack.
.Ss dropn
Remove the n topmost elements of the stack.
.Bd -literal
4:                 2.00
3:                33.00
2:                44.00
1:                55.00
> 3 dropn

4:
3:
2:
1:                 2.00
>
.Ed
.Ss drop2
Shortcut for 2 dropn.
.Ss drop
Shortcut for 1 dropn.
.Ss dupn
Duplicate the n topmost elements of the stack.
.Bd -literal
4:
3:
2:                 3.14
1:                34.00
> 2 dupn

4:                 3.14
3:                34.00
2:                 3.14
1:                34.00
>
.Ed
.Ss dup2
Shortcut for 2 dupn.
.Ss dup
Shortcut for 1 dupn.
.Ss pick
Pick an element in the stack and copy it at the top of the stack.
.Bd -literal
4:
3:               123.00
2:                33.00
1:                44.00
> 3 pick

4:               123.00
3:                33.00
2:                44.00
1:               123.00
>
.Ed
.Ss over
Shortcut for 2 pick.
.Ss roll
Pick an element in the stack and move it at the top of the stack.
.Bd -literal
4:
3:               123.00
2:                33.00
1:                44.00
> 3 roll

4:
3:                33.00
2:                44.00
1:               123.00
>
.Ed
.Ss swap
Shortcut for 2 roll.
.Ss rot
Shortcut for 3 roll.
.Ss rolld
Pick the topmost element and move it downward the stack.
.Bd -literal
4:                 1.00
3:                 2.00
2:                 3.00
1:                 4.00
> 3 rolld

4:                 1.00
3:                 4.00
2:                 2.00
1:                 3.00
>
.Ed
.Ss depth
Push the size of the stack on the stack.
.Sh ARITHMETIC OPERATORS
.Ss add, +
Add two topmost elements of the stack.
.Ss sub, -
Substract two topmost elements of the stack.
.Ss mul, *
Multiply two topmost elements of the stack.
.Ss div, /
Divide two topmost elements of the stack.
.Ss modulo, %
Modulo of two topmost elements of the stack.
.Ss pow
Exponentiation operator of two topmost elements of the stack.
.Ss sq
Shortcut for 2 pow (square value of topmost element).
.Ss sqrt
Shortcut for .5 pow (square root value of topmost element).
.Ss neg
Negate topmost element of the stack.
.Ss abs
Replace topmost element of the stack by its absolute value.
.Ss ceil
Replace topmost element of the stack by its ceiling value.
.Ss floor
Replace topmost element of the stack by its floor value.
.Ss round
Replace topmost element of the stack by its round value.
.Ss sum
Sum every element of the stack.
.Ss avg
Compute average value of the stack.
.Sh COMPARATORS
.Ss equal
Test if second element equals first one.
.Ss le
Test if second element is less or equal compared to first one.
.Ss lt
Test if second element is less than first one.
.Ss ge
Test if second element is greater or equal compared to first one.
.Ss gt
Test if second element is greater than first one.
.Sh BASE NUMBERS
.Nm
accepts numbers in 'base mode' format, using the following syntax:
.Pp
.Bl -tag -width Ds
.It #...b
binary base number (example #01b)
.It #...o
octal base number (example #12o)
.It #...d
decimal base number (example #23d)
.It #...h
hexadecimal base number (example #ea1h)
.El
.Pp
Base numbers are displayed in decimal base by default.
See commands
.Ar bin ,
.Ar oct ,
.Ar dec ,
.Ar hex
to change the default base number display mode.

.Ss base
Turn a float number into a base number.
.Ss float
Turn a base number into a float number.
.Ss bin
Display base numbers in base 2.
.Ss oct
Display base numbers in base 8.
.Ss dec
Display base numbers in base 10.
.Ss hex
Display base numbers in base 16.
.Sh BITWISE OPERATORS
.Ss blshift
Binary left shift operator.
.Bd -literal
4:
3:
2:
1:                 1.00
> 2 blshift

4:
3:
2:
1:                 4.00
>
.Ed
.Ss brshift
Binary right shift operator.
.Ss band
Binary and between two topmost elements.
.Ss bor
Binary or between two topmost elements.
.Ss bxor
Binary xor between two topmost elements.
.Sh CONSTANTS
.Ss pi
The Pi constant.
.Ss e
Natural logarithm.
.Sh TRIGONOMETRY
.Ss cos
Cosinus.
.Ss sin
Sinus.
.Ss tan
Tangent.
.Ss acos
Arc-cosinus.
.Ss asin
Arc-sinus.
.Ss atan
Arc-tangent.
.Ss cosh
Hyperbolic-cosinus.
.Ss sinh
Hyperbolic-sinus.
.Ss tanh
Hyperbolic-tangent.
.Sh LABELS
.Nm
supports the notion of labels, where values can be stored to / retrieved
from. A valid label name is made of alphabetic characters and underscore
character.
.Pp
A label can be entered as is. If a value is already assigned to a label,
the stored value is pushed on the stack. Otherwise, the label name is put
on the stack. To put a label on the stack without evaluation, enter it in
single quotes.
.Ss mem
Dump a list of labels and their associated value.
.Ss sto
Store a value into a label:
.Bd -literal
4:
3:
2:
1:
> 2 'two' sto

4:
3:
2:
1:
> mem

two: 2.00

4:
3:
2:
1:
> two

4:
3:
2:
1:                 2.00
>
.Ed
.Ss sto+
Increment value stored in a label with the topmost value of the stack.
.Bd -literal
4:
3:
2:
1:                 5.00
> 'two' sto+

4:
3:
2:
1:
> two

4:
3:
2:
1:                 7.00
>
.Ed
.Ss rcl
Recall a value stored in a label.
.Bd -literal
4:
3:
2:
1:
> 'two' rcl

4:
3:
2:
1:                 7.00
>
.Ed
.Ss purge
Unassign value stored in a label.
.Bd -literal
4:
3:
2:
1:
> 'two' purge
.Ed
.Sh PROGRAMS
.Ss <<...>>
Sequences of commands can be specified between double angle brackets:
.Bd -literal
4:
3:
2:
1:
> <<3 4 5 6>>

4:
3:
2:
1: <<3.00 4.00 5.00 6.00>
>
.Ed
.Ss eval
A program on top of the stack can be evaluted with the eval command:
.Bd -literal
4:
3:
2:
1: <<3.00 4.00 5.00 6.00>
> eval

4:                 3.00
3:                 4.00
2:                 5.00
1:                 6.00
>
.Ed
.Sh CONTROL FLOW
.Ss ift
If-then conditionnal. Expect a program as a first argument, and an int value
as a second argument. program is evaluated if float value is not zero.
.Bd -literal
4:
3:
2: 1
1: <<3.00 4.00 add>>
> ift

4:
3:
2:
1:                 7.00
>
.Ed
.Ss ifte
If-then-else conditionnal. Expect programs on first and second arguments,
and an int value as a third argument. Evaluate first program if third
argument is not zero, evaluate second program otherwise.
.Bd -literal
4:
3: 0
2: <<1.00 1.00 add>>
1: <<2.00 2.00 mul>>
> ifte

4:
3:
2:
1:                 2.00
>
.Ed
.Ss whileop
While loop operator. Expect programs on first and second arguments.
Evaluate first program as long a second program evaluate to a float
value that is not zero.
.Sh COMMENTS
The '@' character mark the beginning of a comment. Following characters
until EOL are discarded.
.Bd -literal
4:
3:
2:
1:
> @ this is a comment
.Ed
.Sh RCFILE
On startup,
.Nm
parse the $HOME/.config/calc/calcrc if it exists. You can store there
your custom commands. For example, this rc file defines a rgb command
by storing a program into the 'rgb' label:
.Bd -literal
$ cat ~/.config/calc/calcrc
@ 'rgb' command to convert an hexadecimal color value into RGB format
<<dup 16 brshift #ffh band swap dup 8 brshift #ffh band swap #ffh band>> 'rgb' sto

$ calc

4:
3:
2:
1:
> #63c6a5h rgb

4:
3:                 #99d
2:                #198d
1:                #165d
>
.Ed
.Sh AUTHOR
.An Gerome Fournier Aq Mt jef@foutaise.org .

Changes to src/calc/cmds.c.

110
111
112
113
114
115
116
117
118
119


120
121
122
123
124
125
126
...
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
...
824
825
826
827
828
829
830




831
832
833
834
835
836
837
	CMD(bxor),

	/* Conditionnals */
	CMD(ift),
	CMD(ifte),
	CMD(whileop),

	/* Trigonometry */
	CMD(pi),
	CMD(e),


	CMD(cos),
	CMD(sin),
	CMD(tan),
	CMD(acos),
	CMD(asin),
	CMD(atan),
	CMD(cosh),
................................................................................
		cmd_eval();
	}
	token_free(bodyprog);
	token_free(condprog);
}

/*
 * Trigonometry
 */

void
cmd_pi()
{
	struct token *pi;

................................................................................
{
	struct token *e;

	e = token_float(2.71828182845904523536);
	stack_push(e);
}





#define CMD_TRIG(TRIGOP) \
	void \
	cmd_##TRIGOP() \
	{ \
		struct token *t; \
		\
		CMD_ASSERT(TOKEN_FLOAT); \







|


>
>







 







|







 







>
>
>
>







110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
...
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
...
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
	CMD(bxor),

	/* Conditionnals */
	CMD(ift),
	CMD(ifte),
	CMD(whileop),

	/* Constants */
	CMD(pi),
	CMD(e),

	/* Trigonometry */
	CMD(cos),
	CMD(sin),
	CMD(tan),
	CMD(acos),
	CMD(asin),
	CMD(atan),
	CMD(cosh),
................................................................................
		cmd_eval();
	}
	token_free(bodyprog);
	token_free(condprog);
}

/*
 * Constants
 */

void
cmd_pi()
{
	struct token *pi;

................................................................................
{
	struct token *e;

	e = token_float(2.71828182845904523536);
	stack_push(e);
}

/*
 * Trigonometry
 */

#define CMD_TRIG(TRIGOP) \
	void \
	cmd_##TRIGOP() \
	{ \
		struct token *t; \
		\
		CMD_ASSERT(TOKEN_FLOAT); \