Power function question...

This is a discussion on Power function question... within the C Programming forums, part of the General Programming Boards category; long double a1, a2, a3; a1 = 20; a2 = 77; a3 = pow(20, 77) It couoldn't calculate the a3 ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    101

    Power function question...

    long double a1, a2, a3;
    a1 = 20;
    a2 = 77;
    a3 = pow(20, 77)

    It couoldn't calculate the a3 out...
    So, what can I do?? should I use powl?
    or using others?

    thx a lot......

  2. #2
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    To use the pow() function you must use include the math.h header.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    101
    I know... but the result is too big to calculate.....

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    You need to implement a datastructure for huge numbers and define operations on it.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    101
    Originally posted by Shiro
    You need to implement a datastructure for huge numbers and define operations on it.
    Sorry... would you mind telling me more...
    coz... I don't understand.... sorry.....

  6. #6
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    C doesn't have a standard type in which you can store huge numbers. For example the numbers used in cryptography or the search for prime-numbers.

    So if you want to develop applications which need to work with such huge numbers, you need to create a datastructure which can contain the numbers. Since it is your own datastructure, you need to define functions to work with the datastructure by yourself.

    In some other thread some time ago one also asked about how to use large numbers. Then, I guess it was Zahid, someone came with the idea of using strings.

    The number

    12398739487329873498795872938749837492837959283749 87987293487983494827349872962934954353865827364832 768

    cannot be stored in a standard type. But you could use a string to store this number, a linked list would also be a solution. A string can be dynamically allocated an resized. So you can at runtime change the size of the required memory.

    Then you need to write some functions to perform operations with the numbers. Multiplication, adding, substraction, division and perhaps some more advanced things like power, square root or whatever.

  7. #7
    Registered User alex's Avatar
    Join Date
    Sep 2001
    Posts
    132
    Hi!

    Did you wan to compute this modulo some value?

    for multiplication the following equivalence holds:
    (a*b*c)%d = (((a*b)%d)*c)%d

    i.e., you can use the modulo operator after each multiplication...

    Hope this is to-the-point.

    alex

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 09:56 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 11:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21