pow() function

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

pow() function

Postby Sytan » Mon Mar 21, 2011 1:21 am

Hello everyone,

Please allow me to ask about pow() function in math.h for Hi-Tech C compiler. I had tried the following:-

unsigned long temp;

temp = pow(10,1); // i get 10 for my answer *CORRECT
temp = pow(10,2); //i get 100 *CORRECT
temp = pow(10,3); //i get 1000 *CORRECT also

Problems arise when i tried

temp = pow(10,4); //i get 10001 for my answer which is not true for decimal
temp = pow(10,5); //i get 100016 for my answer..
higher power i go the error getting larger.

FYI,i need it in my FOR loop,any other method to get rid of this problem?
Thank you in advance ;)
Sytan
Apprentice
 
Posts: 33
Joined: Mon Jun 07, 2010 3:10 pm

Re: pow() function

Postby Sytan » Mon Mar 21, 2011 1:50 am

sorry
I think i found a way to solve it.
using loop to multiply variable itself will get the exact value i need
eg:-
temp *= X; //where X is your base
Sytan
Apprentice
 
Posts: 33
Joined: Mon Jun 07, 2010 3:10 pm

Re: pow() function

Postby sich » Wed Mar 23, 2011 11:12 pm

Haha...it's good that you found an alternative to get the desired result. About the problem using pow() function, I've no idea why the error occurs :D
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 604
Joined: Tue Apr 21, 2009 2:15 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 5 guests

cron