Doing math with TCC

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
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
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,410
40
Albuquerque, NM
prospero.unm.edu
#2
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
 
#3
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!
 
#4
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
 
#5
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.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,410
40
Albuquerque, NM
prospero.unm.edu
#6
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.
 
#8
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)].
 

samintz

Scott Mintz
May 20, 2008
1,227
11
Solon, OH, USA
#10
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]]
 
#11
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