Thread: non-interger exponents

  1. #1
    Registered User
    Join Date
    Jul 2002

    non-interger exponents

    Is there any way to use fractional exponents? I've tried:
    pow(base, exponent);
    with exponent being 1.2 or so and I've also tried a round-a-bout way to get the answer using:
    and all it seems to do is convert the exponent to a int and then do the math. And also I am using doubles for all my variables.

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Seattle, WA
    Write your own exponent function

    If the function only takes ints for arguments then you cant pass numbers with decimal points...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."

  3. #3
    Registered User
    Join Date
    Nov 2002

    that's weird. it worked for me.

    pow takes two double arguments and returns a double. it should work.

    what compiler?

  4. #4
    Registered User
    Join Date
    Jul 2002
    I'm using the Borland Command Line Compiler (not sure what version, think it's pretty recent.) And I tried hard coding an example:
    cout<<pow10(1.2)<<' '<<pow10(.3);
    and it printed: 10 1

    And on the reply of me writing my own function, I'm not quite sure how to do that without using Log or 10^X. Haven't quite covered that in precal.

  5. #5
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    write a power series for the power function and have a certain level of precision, if you want to write your own power function. For more information look on the net for power series.

    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Works for me
    #include <iostream>
    #include <cmath>
    using namespace std;
    int main ( ) {
        cout<<pow10(1.2)<<' '<<pow10(.3) << endl;
        return 0;
    15.8489 1.99526
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. exponents are LAAAME
    By Sm33zy in forum C Programming
    Replies: 8
    Last Post: 11-21-2008, 10:10 PM
  2. Fraction Exponents
    By ninjaturtle[k9] in forum C++ Programming
    Replies: 4
    Last Post: 10-18-2004, 10:46 AM
  3. Random Interger
    By Seph_31 in forum C Programming
    Replies: 3
    Last Post: 11-21-2003, 01:20 AM
  4. For loop and exponents
    By TrazPFloyd in forum C++ Programming
    Replies: 5
    Last Post: 10-15-2002, 05:19 AM
  5. How to Convert Interger to String?
    By Yin in forum C++ Programming
    Replies: 13
    Last Post: 03-14-2002, 01:37 PM