Point on Line Segment in 2D. Which code is faster ? Can you improve it ?

B

Ben Hetland

Keith said:
Exponentiation (if the language supports it) is just repeated
multiplication.

This is true only for integer exponents!
(As I illustrated with my "a^n" example.)

When the exponent also has a fractional part (as in "a^b"), then it is
not more so trivial. I assume this is true even if the "fractional
exponent" is a "fixed format represented as integer".


-+-Ben-+-
 
J

John Woodgate

I read in sci.electronics.design that Ben Hetland
about 'Point on Line Segment in 2D. Which code is faster ? Can you
improve it ?', on Fri, 23 Sep 2005:
This is true only for integer exponents!
(As I illustrated with my "a^n" example.)

When the exponent also has a fractional part (as in "a^b"), then it is
not more so trivial. I assume this is true even if the "fractional
exponent" is a "fixed format represented as integer".

For rational exponents, the operation involves multiplication and
division, or at least one single division to evaluate a reciprocal.

Irrational and transcendental exponentiation is witchcraft and should be
proscribed. (;-)
 
D

Dik T. Winter

>
> For rational exponents, the operation involves multiplication and
> division, or at least one single division to evaluate a reciprocal.

Only for integer exponents, for rational non-integral exponents you
need also roots. E.g. a^(1/2) = sqrt(a).
 
J

John Woodgate

I read in sci.electronics.design that Dik T. Winter <[email protected]>
wrote (in said:
For rational exponents, the operation involves multiplication and
division, or at least one single division to evaluate a reciprocal.

Only for integer exponents, for rational non-integral exponents you
need also roots. E.g. a^(1/2) = sqrt(a).[/QUOTE]

They can be calculated to any desired degree of precision by
multiplication. Look up 'co-factors', which is how we used to find
square roots on a mechanical calculator.
 
D

Dik T. Winter

> I read in sci.electronics.design that Dik T. Winter <[email protected]>
> wrote (in <[email protected]>) about 'Point on Line Segment in 2D. Which
> code is faster ? Can you improve it ?', on Fri, 23 Sep 2005: ....
>
> They can be calculated to any desired degree of precision by
> multiplication. Look up 'co-factors', which is how we used to find
> square roots on a mechanical calculator.

I know how to calculate square roots etc. Thank you very much. But
with your characterisation you can calculate *all* numbers of the form
a^b by only the operations multiplication and division, addition and
subtraction.
 
K

Keith Thompson

Ben Hetland said:
This is true only for integer exponents!
(As I illustrated with my "a^n" example.)

When the exponent also has a fractional part (as in "a^b"), then it is
not more so trivial. I assume this is true even if the "fractional
exponent" is a "fixed format represented as integer".

That's true -- but if you're dealing with exponentation with a
non-integer exponent, you probably want to use floating-point anyway.

If you really need to compute a=b**c, where a, b, and c are all
fixed-point, you're likely to be better off converting b and c to
floating-point and then converting the result back to fixed-point.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top