1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Doing math with TCC

Discussion in 'Support' started by pb4072, Jun 27, 2016.

  1. pb4072

    Joined:
    Jul 25, 2008
    Messages:
    33
    Likes Received:
    0
    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
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,312
    Likes Received:
    39
    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. pb4072

    Joined:
    Jul 25, 2008
    Messages:
    33
    Likes Received:
    0
    Thanks.

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

    Joined:
    May 20, 2008
    Messages:
    7,972
    Likes Received:
    30
    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. pb4072

    Joined:
    Jul 25, 2008
    Messages:
    33
    Likes Received:
    0

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

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,312
    Likes Received:
    39
    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.
     
  7. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,312
    Likes Received:
    39
    Either I'd forgotten that, or I never knew it in the first place. In TCC, it does support floating point.
     
  8. WavSlave

    Joined:
    May 29, 2008
    Messages:
    47
    Likes Received:
    0
    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)].
     
  9. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,972
    Likes Received:
    30
    That's about as straightforward as it gets!
     
  10. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,191
    Likes Received:
    11
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,972
    Likes Received:
    30
    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
     
  12. WavSlave

    Joined:
    May 29, 2008
    Messages:
    47
    Likes Received:
    0
    ...says the mathematics professor. :smile:
     

Share This Page