Start a new topic
Answered

More info on using Math variable

In 7.3 the ability to compute basic math expressions in CrushTask variables was added. Aside from a cryptic crush task example in the Wiki, can you elaborate or add a wiki page explaining the tag(s) and what they do/are capable of please...


Thanks, TJ


Best Answer

You can use an expression like this:


{math_start}5+5{math_end}


Or...


{math_start}{size}/1024{math_end}Kb


Etc.


Its basic math expressions will be handled between those tags.  Other variables are replaced first.


Thanks,

Ben



Answer

You can use an expression like this:


{math_start}5+5{math_end}


Or...


{math_start}{size}/1024{math_end}Kb


Etc.


Its basic math expressions will be handled between those tags.  Other variables are replaced first.


Thanks,

Ben


Can you compound them? i.e. Crush talks in bytes, to represent the same as MiB can you do {math_start}{size}/1024/1024{math_end} Mib?


As the example in the wiki has a {math_start:l} I didn't know if the ":I" was a type or something else. 

{math_start:l}{now}-{parse_start:MM/dd/yyyy hh:mm:ss aa}{expire_password_when}{parse_end}{math_end}

 

In the example there is also use of the {parse} variable - how is that used? Is that a formatting option?


TJ

It will evaluate the entire expression...but keep things simple, its not an advanced expression handler.  Two divisions is fine though.


If you don't specify :i in the start, its assumed to be an integer for the result.  Otherwise you can do d for double and f for float.


{math_start:f}5/2{math_end}


Thanks,

Ben

Ok, thanks. I assume you can't nest math commands, e.g {math_start}{math_start}{size}/1024{math_end}/1024{math_end}, so I suppose I can just divide the bytes by 1048576 to get the MiB equivalent...


TJ

If you use a float can you limit the decimal places?


TJ

no...

Nesting might work...haven't tried.  But this should be fine too...


{size}/1024/1024


Or even:


({size/1024)/1024


And so on.

Login to post a comment