Re: POWER()

new topic     » goto parent     » topic index » view thread      » older message » newer message

Robert Craig wrote:
> Hawke writes:
>> It says in library.doc that powers of 2 are calculated very
>> efficiently.
> By "power of 2", I meant power(2,n) where n is a fairly small
> positive integer (from 0 to 29).
DOH! i knew dat :)
okay... so i didnt... ;)


>> It seems that power(x,2) is not quite right as far as speed.
this is the part that i'm actually worried about...

when x*x returns the same value (int,atom,sequence) as
power(x,2) between 3 and 30 times faster...
ummmm sumfin wrong dontcha think?

i could understand like 29.2 seconds versus 29.7 seconds,
or sumfin like that... but...
squares are real common, you know?
dare we try benchmarking cubes???
(not quite as common, but still used a lot in certain
formulas: cubic footage/volume, & air flow for starters)

i'm not complaining mind you... it's just a dilemma that
i happened to notice and thought should be pointed out...

I would, however, like to make a formal request for
an addition to Euphoria syntax.

It meets the following requirements:
  1>Does it improve or uphold readability/clean coding? yes.
  2>Does it enhance Euphoria, perhaps giving it
    compliance with known standards/conventions? yes.
  3>Would it be used? most assuredly.
  4>Would it slow Euphoria down? no, in fact, it may
    speed certain things up, as it will reduce function
    calls for a commonly used activity.
  5>Would it be difficult to implement? shouldn't be...
  6>Would it represent a "hack"? no.
  7>Would it hinder maintainability? no.

This request is simply the addition of the caret "^"
to the list of mathmatics operators for indicating
an object is to be raised to a power of.

The caveat is that objects on the righthand might
be less than 1.
  25^0.5
  {3,4,5}^{2,1/2,-2}
well, those examples get a little wierd...

I would be happy if, at the point this suggestion was
implemented, only values/objects greater than 1
were allowed on the righthand side...
at least until we all discuss this and determine
what we want done with objects <1 on the right...

If we restricted the righthand side to only integers
1 or higher, then very fast optimizations could be made
for the "^" and power() used for the 'tricky' cases...

I would also be happy, ecstatic in fact, if the
^ simply replaced power(), especially if it
reduced any function calling overhead.

--Hawke'

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu