Author
|
Message
|
Paul Etienney
|
Wednesday 15 October 2008 2:11:50 am
Hello everyone, Is there a mean to use math formulas including power of For exemple
{def $nine = 3|powerof(3)} {$nine} would display : 27
Thank you Have a good day
-- Good websites creation --
My site : http://www.pauletienney.com
Twitter : http://www.twitter.com/p_etienney
|
André R.
|
Wednesday 15 October 2008 3:17:24 am
Are you sure? Cause last time I checked 3*3*3 was somewhere around 27 :)
You'll need to do a custom template operator if you want it to be fully flexible. But if you always use ^3, then something like this will do:
{def $in = 3
$out = $in|mul( $in, $in )}
{$out}
eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom
|
Paul Etienney
|
Wednesday 15 October 2008 3:59:27 am
Sure this is 27 ! Do you know if there is contribution to do this ? I am not a developper at all and my english is not perfect. I did not find anything.
-- Good websites creation --
My site : http://www.pauletienney.com
Twitter : http://www.twitter.com/p_etienney
|
André R.
|
Wednesday 15 October 2008 4:10:03 am
Not that I know of, you could solve it in template if you want to, but performance wise it's not the best solution of course:
{def $in = 3
$powerof = 3
$out = $in}
{for 1 to $powerof as $counter}
{set $out = $out|mul( $in )}
{/for}
{$out}
eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom
|
Paul Etienney
|
Wednesday 15 October 2008 4:28:29 am
I found in /lib/ezmath/classes/mathhandlers/ezphpmath.php the pow function (line : 77) Is it working ? I tried :
{def $neuf = 3|pow('3')} {$neuf} but it displays 3 ! This function is not in the doc. May i use it ?
-- Good websites creation --
My site : http://www.pauletienney.com
Twitter : http://www.twitter.com/p_etienney
|
André R.
|
Wednesday 15 October 2008 5:03:24 am
As far as I can see it's not used by any template operators, so your code there probably generates a debug warning that there is no template operator named pow. But you can use a setting called PHPOperatorList in template.ini* to register the php pow** function:
[PHP]
PHPOperatorList[phppow]=pow
And use it like:
{def $nine = 3|phppow(3)}
{$nine}
* place the setting in settings/override/template.ini.append.php ** http://no2.php.net/pow
eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom
|
Paul Etienney
|
Wednesday 15 October 2008 5:19:02 am
The debug says : pow() expects exactly 2 parameters, 1 given in C:\wamp\www\sphinx-extranet\lib\eztemplate\classes\eztemplatephpoperator.php on line 118 So i tried
{def $nine = phppow(3, 3)} {$nine} The debug is the same
-- Good websites creation --
My site : http://www.pauletienney.com
Twitter : http://www.twitter.com/p_etienney
|
André R.
|
Wednesday 15 October 2008 5:25:38 am
Ok, then it seems that PHPOperatorList can only take 1 parameter, so only suitable for really simple functions. Updated the template solution above now, so it should work.
eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom
|
Paul Etienney
|
Wednesday 15 October 2008 6:23:29 am
Ok I am trying with 'template' solution. The code is ok but my variable displays INF if I try :
{for 1 to 300 as $counter}
{set $MensualiteBas = $MensualiteBas|mul( $MensualiteBas )} {/for} What is it ?
-- Good websites creation --
My site : http://www.pauletienney.com
Twitter : http://www.twitter.com/p_etienney
|
André R.
|
Wednesday 15 October 2008 6:36:39 am
You have probably reached the ceiling of integer type*. But that can probably be avoided if you fix your code to do what I showed above (you used the example from before I updated it). * http://no.php.net/int
The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed).
eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom
|
Paul Etienney
|
Wednesday 15 October 2008 6:53:53 am
I used the last version of your post. I just adapted it. {def $DureeMois = '300'} {def $Taux = '0.055'} {def $MensualiteBas = $Taux|sum(1)}
{for 1 to $DureeMois as $counter}
{set $MensualiteBas = $MensualiteBas|mul( $MensualiteBas )} {/for} {$MensualiteBas} It displays INF I love eZ Publish but this hard to calculate things.
-- Good websites creation --
My site : http://www.pauletienney.com
Twitter : http://www.twitter.com/p_etienney
|
André R.
|
Wednesday 15 October 2008 7:00:28 am
{def $DureeMois = 300
$Taux = 0.055
$MensualiteBas = $Taux|sum( 1 )
$outValue = $MensualiteBas}
{for 1 to $DureeMois as $counter}
{set $outValue = $outValue|mul( $MensualiteBas )}
{/for}
{$outValue}
In the code you have(and I had earlier) it will (if it was 3^3) be:
3*3
9*9 = 81 Do that 'small' mistake 300 times and you end up with a very large number..
eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom
|
Paul Etienney
|
Thursday 16 October 2008 3:44:00 am
Thank you very much. This is fixed.
-- Good websites creation --
My site : http://www.pauletienney.com
Twitter : http://www.twitter.com/p_etienney
|