Mathematics Operators : power of - ^ - superior [Resolved]

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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 04:20:24
Script start
Timing: Jan 19 2025 04:20:24
Module start 'layout'
Timing: Jan 19 2025 04:20:24
Module start 'content'
Timing: Jan 19 2025 04:20:24
Module end 'content'
Timing: Jan 19 2025 04:20:24
Script end

Main resources:

Total runtime0.0157 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0052 590.4219152.6406
Module start 'layout' 0.00520.0036 743.062539.4766
Module start 'content' 0.00870.0048 782.5391113.5234
Module end 'content' 0.01360.0021 896.062554.3047
Script end 0.0157  950.3672 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002515.8707140.0002
Check MTime0.00116.8139140.0001
Mysql Total
Database connection0.00074.351010.0007
Mysqli_queries0.003320.837430.0011
Looping result0.00000.185010.0000
Template Total0.001811.610.0018
Template load0.00106.113210.0010
Template processing0.00095.438410.0009
Override
Cache load0.00063.657910.0006
General
dbfile0.00031.736580.0000
String conversion0.00000.191140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs