Forums / Setup & design / Mathematics Operators : power of - ^ - superior [Resolved]

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

eZ debug

Timing: Jan 31 2025 08:20:57
Script start
Timing: Jan 31 2025 08:20:57
Module start 'content'
Timing: Jan 31 2025 08:20:57
Module end 'content'
Timing: Jan 31 2025 08:20:57
Script end

Main resources:

Total runtime0.1825 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0079 588.0781180.8125
Module start 'content' 0.00790.0064 768.8906118.0859
Module end 'content' 0.01430.1681 886.9766546.2969
Script end 0.1824  1,433.2734 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00351.9254200.0002
Check MTime0.00140.7923200.0001
Mysql Total
Database connection0.00120.684410.0012
Mysqli_queries0.135073.94991410.0010
Looping result0.00100.57471390.0000
Template Total0.167791.910.1677
Template load0.00090.486610.0009
Template processing0.166891.368110.1668
Override
Cache load0.00060.321110.0006
Sytem overhead
Fetch class attribute can translate value0.00100.566010.0010
XML
Image XML parsing0.00030.151310.0003
General
dbfile0.00904.9318200.0005
String conversion0.00000.003330.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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