# Doing math with TCC

#### pb4072

Hello,
Can someone tell me how to do simple math with TCC? I need to divide the height versus the width of PDF files, which I get from a "pdfinfo" utility. I need that ratio so that I can use it to make SVG files from the PDFs, at particular sizes.

Thanks,
Peter

One way is to use the %@EVAL function:
Code:
``set aspect=%@eval[%height / %width]``

Or you can use SET /A, which works much like in CMD.EXE but without the octal support biting you at odd moments:
Code:
``set /a aspect=%height / %width``

Thanks.
One way is to use the %@EVAL function:
Code:
``set aspect=%@eval[%height / %width]``

Or you can use SET /A, which works much like in CMD.EXE but without the octal support biting you at odd moments:
Code:
``set /a aspect=%height / %width``

Thanks. Yeh, I've tried the "set /a" stuff in the command shell, but, it doesn't support floating numbers. I'll play with the eval thing. Thanks again!

CMD may not, but TCC's SET /A supports floats.
Code:
``````v:\> set /a float=8/3
2.6666666667

v:\> set /a float*=.5
1.3333333334``````
@EVAL just works better.
Code:
``````v:\> echo %@eval[8/3 * .5]
1.3333333333``````

CMD may not, but TCC's SET /A supports floats.
Code:
``````v:\> set /a float=8/3
2.6666666667

v:\> set /a float*=.5
1.3333333334``````
@EVAL just works better.
Code:
``````v:\> echo %@eval[8/3 * .5]
1.3333333333``````
CMD may not, but TCC's SET /A supports floats.
Code:
``````v:\> set /a float=8/3
2.6666666667

v:\> set /a float*=.5
1.3333333334``````
@EVAL just works better.
Code:
``````v:\> echo %@eval[8/3 * .5]
1.3333333333``````

Thanks. Yeh, I got %@eval to work for me.
Cheers.

CMD may not, but TCC's SET /A supports floats.
Code:
``````v:\> set /a float=8/3
2.6666666667

v:\> set /a float*=.5
1.3333333334``````
@EVAL just works better.
Code:
``````v:\> echo %@eval[8/3 * .5]
1.3333333333``````

Is it really any different?
Code:
``````C:\>set /a float=8 / 3 * .5
1.3333333333

C:\>``````

It's probably the same engine under the hood. Rex isn't one to write two different routines to accomplish the same task.

Thanks. Yeh, I've tried the "set /a" stuff in the command shell, but, it doesn't support floating numbers.

Either I'd forgotten that, or I never knew it in the first place. In TCC, it does support floating point.

pb4072, @EVAL lets you do some pretty advanced math as well. It supports exponentiation, bit-manipulation operations, logarithms, trigonometric functions, etc., etc. Want to know what pi is out to 15,000 decimal places? It's got that covered. It's really quite a powerful function should you ever need any of those facilities.

If I have any (very minor) gripe about it, it's that it has no particularly straightforward way to compute roots but I figured out how to get it to do those, too. You can do that by raising a number to the power of the reciprocal of the root you're trying to find. E.g., to find the cube root of n, use @EVAL[n**(1/3)].

E.g., to find the cube root of n, use @EVAL[n**(1/3)].
That's about as straightforward as it gets!

pb4072, @EVAL lets you do some pretty advanced math as well. It supports exponentiation, bit-manipulation operations, logarithms, trigonometric functions, etc., etc. Want to know what pi is out to 15,000 decimal places? It's got that covered. It's really quite a powerful function should you ever need any of those facilities.

If I have any (very minor) gripe about it, it's that it has no particularly straightforward way to compute roots but I figured out how to get it to do those, too. You can do that by raising a number to the power of the reciprocal of the root you're trying to find. E.g., to find the cube root of n, use @EVAL[n**(1/3)].

You *could* create functions to do that if you need it often.
Code:
``````function SQR=`%@eval[%1 ** 0.5]`
function ROOTn=`%@eval[%1 ** (1/%2)]`
function Root=`%@eval[10**(log10(%1)/%2)]`

echo Square root of 2=%@SQR[2],^ncubed root of 2=%@ROOTn[2,3]^nanother cubed root=%@Root[2,3]

echo %@eval[ 2 * %@sqr[2]]``````

You don't even need to call %EVAL if you know you'll be in @EVAL anyway.
Code:
``````v:\> function root `(%1**(1/%2))`

v:\> echo %@root[8,3]
(8**(1/3))

v:\> echo %@eval[%@root[8,3]]
2``````

That's about as straightforward as it gets!
...says the mathematics professor.

Replies
5
Views
2K
Replies
1
Views
1K
Replies
3
Views
1K
Replies
10
Views
2K
Replies
1
Views
1K
Replies
11
Views
3K
Replies
12
Views
2K
Replies
4
Views
1K
Replies
2
Views
1K
Replies
3
Views
1K
Replies
7
Views
8K
Replies
17
Views
3K
Replies
6
Views
2K
Replies
12
Views
2K
Replies
9
Views
129
Replies
2
Views
93
Replies
0
Views
77
Replies
7
Views
179
Replies
8
Views
245
Replies
6
Views
170
Replies
15
Views
336
Replies
0
Views
116
Replies
1
Views
184
Replies
4
Views
194
Replies
0
Views
190
Replies
2
Views
180
Replies
17
Views
390
Replies
2
Views
268
Replies
19
Views
527
Replies
27
Views
596
Replies
9
Views
367
Replies
5
Views
420
Replies
14
Views
632
Replies
25
Views
974
Replies
1
Views
311
Replies
1
Views
316
Replies
2
Views
412
Replies
5
Views
737
Replies
2
Views
456
Replies
11
Views
773
Replies
16
Views
806
Replies
2
Views
461
Replies
2
Views
449
Replies
0
Views
478
Replies
1
Views
418
Replies
6
Views
827
Replies
6
Views
706
Replies
0
Views
562
Replies
2
Views
557
Replies
6
Views
921