Lasso Soft Inc. > Home

[lp_math_mod]

Linklp_math_mod
AuthorBil Corry
CategoryMath
Version8.x
LicensePublic Domain
Posted12 Feb 2006
Updated12 Feb 2006
More by this author...

Description

Returns the modulo given a numerator and denominator.  Works around LP8.1 math_mod that returns string type and it works around LP8.1 mod operator '%' that only works with integers.

Note that this implements "truncation towards zero" which is technically not modulo, but more in line with what most people expect.

More info here: http://mathforum.org/library/drmath/view/52343.html

Requires [lp_decimal_precisionset] [lp_decimal_fixed]

Sample Usage

lp_math_mod: 10.5, 2; // 0.5

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

[

define_tag: 'lp_math_mod',
	-description='Returns the modulo given a numerator and denominator.',
	-priority='replace',
	-required='numerator',
	-required='denominator';

	// works around LP8.1 math_mod that returns string type
	// and it works around LP8.1 mod operator '%' that only works with integers
	
	// note that this implements "truncation towards zero" which is technically not modulo, but more in line with what most people expect
	// more info here: http://mathforum.org/library/drmath/view/52343.html

	return: (lp_decimal_precisionset: (decimal: #numerator) - (decimal: #denominator) * (lp_decimal_fixed: (decimal: #numerator) / (decimal: #denominator)));

/define_tag;

]

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft