Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / some c programmers here?

Author
Message
The Big Babou
21
Years of Service
User Offline
Joined: 10th Feb 2003
Location: Cyberspace
Posted: 1st Dec 2003 22:09
if so, could you tell me how the DBP code 3^3 is written in c? i know that is is a totally newbie question, but thats what i am to c. thank you
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Dec 2003 22:21
Result# = 3 ^ 3

becomes

Result = pow(3,3)
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 1st Dec 2003 22:29
You could also do :

result=3*3*3; Its possible the compiler would reduce this trite example to result=27;


Mirrors are more fun than television. Well, that was fun, in a not-so-fun sort of way...
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Dec 2003 22:31
It would probably do the same for the POW function - they tend to be implemented as a built-in function in the compiler
The Big Babou
21
Years of Service
User Offline
Joined: 10th Feb 2003
Location: Cyberspace
Posted: 1st Dec 2003 22:40 Edited at: 1st Dec 2003 22:41
and again the db forum members prove themselves as helpful and nice people. i was searching for the pow function. thank you two
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 1st Dec 2003 22:50
I thought POW was a function - never used it actually...


Mirrors are more fun than television. Well, that was fun, in a not-so-fun sort of way...
TheAbomb12
21
Years of Service
User Offline
Joined: 14th Aug 2003
Location: Amist the blue skies...
Posted: 2nd Dec 2003 01:21 Edited at: 2nd Dec 2003 01:21
Quote: "It would probably do the same for the POW function - they tend to be implemented as a built-in function in the compiler"


dont you need "math.h"?? just to be on the safe side, we don't know what compiler he is using...

Amist the Blue Skies...
The Big Babou
21
Years of Service
User Offline
Joined: 10th Feb 2003
Location: Cyberspace
Posted: 2nd Dec 2003 03:28
I'm using the gcc compiler (with Dev-C++) and it seems he doesn't know the pow function, but i had math.h already included.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Dec 2003 13:16
My bad ... try powf instead.

Just because the function may be built-in, doesn't mean that you don't need a header file for it.

In fact, with GCC, it appears that it isn't a built-in for powf, but there is for other commands. But if you don't include math.h, you won't get the built-in functions because they are defined under different names and use the preprocessor to translate to the fast versions.
The Big Babou
21
Years of Service
User Offline
Joined: 10th Feb 2003
Location: Cyberspace
Posted: 2nd Dec 2003 15:25
now as i'm reading my last post, it sounds that it didn't work to me. but the pow function worked. thanks again IanM. I didn't know the compiler can have inbuilt functions too, i thought you have to include the right header file for a function. well at least i had already math.h included, so that pow() worked fine.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Dec 2003 18:16
Built-in functions are compiler specific - there is no guarantee that a compiler will provide any at all, but generally you will still need to include the correct headers

Login to post a reply

Server time is: 2024-11-24 06:43:27
Your offset time is: 2024-11-24 06:43:27