Shop OBEX P1 Docs P2 Docs Learn Events
To the power of? — Parallax Forums

To the power of?

PatMPatM Posts: 72
edited 2007-09-03 18:57 in Propeller 1
I've been searching the prop manual but I can't seem to find an exponent operator. How do you do something like

val := 10 ^ 6 ?

Yes, I learned quickly that the carat isn't what I need [noparse];)[/noparse]


·

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-09-03 05:26
    You can use Cam Tompson's Floating point library availible from the object exchange.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • LeonLeon Posts: 7,620
    edited 2007-09-03 08:49
    If it's an integer power you could use a loop to calculate it, as is done with the C pow function.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • PatMPatM Posts: 72
    edited 2007-09-03 15:10
    Actually, a loop was exactly what I used last night so I could continue experimenting. Guess I'll keep it [noparse];)[/noparse]
  • rjo_rjo_ Posts: 1,825
    edited 2007-09-03 18:54
    Depends on exactly what you are doing.

    If you need isolated values of a^b then use loops... if you need results from a tight series of a values, then there is a way to speed up the calculations. As a crude "rule of thumb," for "this" to be of any advantage the number of consecutive values of a needs to exceed the average value of b.

    Example shows 100 consecutive values of x^2 and x^3. Since series of a can start anywhere... it is usually necessary to caluculate seed values from a limited series of looped calculations.
    348 x 645 - 223K
  • rjo_rjo_ Posts: 1,825
    edited 2007-09-03 18:57
    oops... I didn't see my spin file... "There it is[noparse]:)[/noparse]
Sign In or Register to comment.