r/C_Programming • u/Horror_Wiener_6102 • Oct 09 '26
Question Newbie in need of Help !
Am I obliged to use a double when using 'pow'? Can't I use a float or an int ? Because for the function 'switch' I have to use int , but I need to use pow for the exercice I'm doing. I chated with Gemini and it told me that I can transform the result of 'pow' into 'int' writing the following; "(int)pow(x, y);". Is this the only way or do I have a faster route to get to my solution? Thanks
1
Upvotes
4
u/flyingron Oct 09 '26
There are also powf and powl, but they're still floating-point. C lacks an integer power function.
3
u/matt9k Oct 09 '26
If you must use pow() for the exercise, then casting the result (the thing with the parentheses) is the easiest way to get an int back
1
u/TomB1952 Oct 09 '26
There's nothing particularly wrong with what you're doing but I cannot imagine a scenario in which a conversion from scientific notation would be used in a switch ladder. Very odd but I understand you are asked to do unusual things in class exercises.
Keep in mind, switch can only match equivalency or the default case for no match.
0
u/Rararror Oct 10 '26
So you are studying C and you need to ask Gemini to use a type cast?
What exactly are you "studying" ?!
0
u/Dazzling_Music_2411 Oct 10 '26
Just write your own simple pow(m,n) function using ints and a loop.