Arithmetic, December 23, 2004

Math is tough...

About the photo... I was originally going to take a photo of something related to numbers or math, but as I was leaving work, I saw a kind of cool shot...

Arithmetic

"Arithmetic" is a Movable Type plugin that provide ssimple arithmetic operations (addition, subtraction, multiplication,and division).

Information

Version
1.0.1
Last Modified
30 November 2005
Download
arithmetic-1.0.1.zip
License
This work is licensed under a Creative Commons License.

Requirements

The "arithmetic" plugin depends on the "Expressions" plugin by Adam Kalsey (http://kalsey.com/blog/2003/01/expressions/).

Installation

Copy arithmetic.pl into the plugins directory under your Movable Type installation directory.

Your installation should look like this:

(mt home)/plugins/arithmetic.pl

Tag Reference

  • <MTAdd> - adds one number to another
  • <MTSubtract> - subtracts one number from another
  • <MTMultiply> - multiplies one number by another
  • <MTDivide> - divides one number by another
  • <MTSetVar2> - assigns a value to a variable
  • <MTGetVar2> - obtains the value of a variable
  • <MTAddVar> - adds a number to the value in a variable
  • <MTSubtractVar> - subtracts a number from the value in a variable
  • <MTMultiplyVar> - multiplies a value in a variable by a number
  • <MTDivideVar> - divides a value in a variable by a number

<MTAdd>

Outputs the result of adding one number (y) to another (x).

Attributes:

  • x - the first number
  • y - the second number

<MTSubtract>

Outputs the result of subtracting one number (y) from another (x).

Attributes:

  • x - the first number
  • y - the second number

<MTMultiply>

Outputs the result of multiplying one number (x) by another (y).

Attributes:

  • x - the first number
  • y - the second number

<MTDivide>

Outputs the result of dividing one number (x) by another (y).

Attributes:

  • x - the first number
  • y - the second number

<MTSetVar2>

Identical to the built-in <MTSetVar> tag, but is able to evaluate a nested MT tag.

Attributes:

  • name - the name of the variable
  • value - the value of the variable

<MTGetVar2>

Identical to the built-in <MTGetVar> tag, but is able to evaluate a nested MT tag.

Attributes:

  • name - the name of the variable

<MTAddVar>

Adds a number (value) to the value already stored in a variable (specified by name).

Attributes:

  • name - the name of the variable
  • value - the value to add

<MTSubtractVar>

Subtracts a number (value) to the value already stored in a variable (specified by name).

Attributes:

  • name - the name of the variable
  • value - the value to subtract

<MTMultiplyVar>

Multiplies a value stored in a variable (name) by a specified number (value).

Attributes:

  • name - the name of the variable
  • value - the value by which to multiply

<MTDivideVar>

Divides a value stored in a variable (name) by a specified number (value).

Attributes:

  • name - the name of the variable
  • value - the value by which to divide

Examples

<MTAdd x="2" y="2"> results in "4" being output.

<MTSetVar2 name="foo" value="2"> followed by <MTAddVar name="foo" value="2"> followed by <MTGetVar2 name="foo"> results in "4" being output.

<MTSetVar2 name="foo" value="2"> followed by <MTAddVar name="foo" value="[MTMultiply x='2' y='20']"> followed by <MTGetVar2 name="foo"> results in "42" being output.

 

Comments


I'm using the plugin on this very page. There's an image map behind each photo. If you click on the left side of the photo, it takes you to the previous image. The right side takes you to the next image.



The map dimensions are calculated using information from the ImageInfo plugin to obtain the width and height of the image, and the arithmetic plugin to calculate half the width (minus one).


Posted by Ted on December 23, 2004 at 12:45:19 PM GMT


Hi, will this work in a loop? i.e, can it be used to increment a value in an MTEntries loop, so each entry has a incremental increase (or decrease or whatever)?

Posted by Stephen on February 9, 2005 at 4:52:45 PM GMT


The answer is yes, it can :)

Posted by Stephen on February 9, 2005 at 8:08:20 AM GMT


Having a bit of trouble with this and I'm feeling particularly stupid about it. Installed both this and Expressions plugins and tried copy/pasting some of the examples, but it just won't parse, not even the simplest example (<MTAdd x="2" y="2">). Any tips for me?

I'm using MT 3.14 install... would that have something to do with it?

Posted by Kass on March 1, 2005 at 10:38:39 AM GMT


First time using MT and your plugin.
What is this error mean?


Plugin error:
Can't locate MTPlugins/Expressions.pm in @INC (@INC contains: /home/junrodesign/www/www/mt/plugins/spamlookup/lib /home/junrodesign/www/www/mt/extlib lib /usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /usr/lib/perl5/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/site_perl/5.6.0/i386-linux /usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.6.1/i386-linux /usr/lib/perl5/vendor_perl/5.6.1 /usr/lib/perl5/vendor_perl .) at /home/junrodesign/www/www/mt/plugins/arithmetic.pl line 40. BEGIN failed--compilation aborted at /home/junrodesign/www/www/mt/plugins/arithmetic.pl line 40. Compilation failed in require at lib/MT.pm line 551.

Posted by Andrew on September 2, 2005 at 10:48:24 AM GMT


i also have that problem, just updated to MT 3.2, it worked fine in MT 3.17 though. sigh, someone please help, what is that plugin error and how do i fix it?

Posted by ken on October 8, 2005 at 11:06:24 AM GMT


The link to download arithmetic.zip says the file is unavailable. Can anyone supply it to me?

Posted by Joe Mendel on November 5, 2005 at 2:38:10 PM GMT


I managed to get plugin to work.
I'm using MT 3.2 with win 2003 server
I changed "MTPlugins" in arithmetic.pl file to "Plugins" and it seemed to do the trick. There were 10 instances of "MTPlugins" which changed. Hope this helps...

Posted by Kevin Kelly on November 10, 2005 at 6:58:55 PM GMT


> i also have that problem, just updated to MT 3.2

Just fix
package MT::Plugin::Arithmetic;
^^^^^^^
to
package MT::Plugins::Arithmetic;
^^^^^^^

I can use fine with this.

Posted by yukikun on November 11, 2005 at 5:31:10 PM GMT


Thank you to all of you who pointed out a bug in the plugin that prevents it from working on MT 3.2. I've uploaded a new arithmetic.zip with the change already made.

Posted by ted on November 30, 2005 at 8:40:58 PM GMT


Hi - I'm running Arithmetic on MT 3.2 and it doesn't seem to work - I get this error when I rebuild. I installed it following the directions, made sure the file was chmod a+rx and I'm not sure what else to do - thanks!

No handler exists for tag SetVar2 at lib/MT/Builder.pm line 170.
No handler exists for tag GetVar2 at lib/MT/Builder.pm line 170.

thanks!!!
morgan

Posted by Morgan on May 7, 2006 at 4:59:32 AM GMT-04:00


Leave a comment

I'm no longer accepting comments on this entry.
Feel free to contact me at eatbitter(at)gmail(dot)com.

« Previous | Next »
0 1 2 3 4 5 6 7 8 9 a b c d e f