• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

dragonsimoto

how do u take a number to the power of

16 posts in this topic

equal = (num1^num2); i get zero for the answer when i do this with any number combos why dont it work? what is the correct way to do powers of? thanks, dragon
0

Share this post


Link to post
Share on other sites
now when i take the pow of some rather large powers, it gives me the same number but smaller pows work perfect. if u know this one let me know if not no big deal.
0

Share this post


Link to post
Share on other sites
perhaps the resulting big-ass number doesn''t fit in your data type? i think pow() returns a double, but are you putting it in an int or something?
0

Share this post


Link to post
Share on other sites
you could always do a while loop, or even better, bitwise operators if your just doing a square, or square root
0

Share this post


Link to post
Share on other sites
You could create your own function for a little coding practice...
Example:

float ComputeExponent(float base, float exponent)
{
int index;
float endresult = base;
for(index = 0; index < exponent - 1; index++)
endresult *= base;

return endresult;
}

Cheers,
-Jesse

| The Hitchhiker''''s Guide to Programming |
"That is not dead which can eternal lie,
And with strange aeons even death may die."
-H.P. Lovecraft
0

Share this post


Link to post
Share on other sites
Just for practice, I think I'll write a little recursiev power function here:
      
double power(float number, float exponent) {
if (exponent == 0)
return 1;//Power of 0 is always 1


if (exponent == 1)
return number;//Power of 1 is the number itself


if (exponent < 0)
return (1 / power(number,(-1 * exponent)));//power less than 0 makes it go to bottom of fraction (reciprecal))


if (exponent > 0 && exponent < 1)
/*Um....fractional exponents...fractional exponents.....
12 ^ .25 is the same as the 4th root of 12....I don't know of any
to the xth root function...if you know (lets say for this example we'll
call it roots(float number, int toTheXthRoot), take the exponent, turn
it into a fraction (you'll have to find/make a function for that,
too), the top part of the fraction being the divisor, the bottom
the denominator, you'll have to return roots(power(number, devisor),
denominator);*/


return (number * power(number, exponent - 1);//12^3 == 12 * 12^2 == 12 * 12 * 12

}


[Edit: It's no fun having to scroll several pages to the right to read a post]

[Edit: Let me have my fun..... ]

"I've learned something today: It doesn't matter if you're white, or if you're black...the only color that REALLY matters is green"
-Peter Griffin

Edited by - Oluseyi on February 17, 2002 5:09:50 PM

Edited by - matrix2113 on February 18, 2002 10:39:41 PM
0

Share this post


Link to post
Share on other sites
Just because we can:

  
template <int power> double exponentiate(float number)
{
return exponentiate<power - 1>(number);
}
.
template double <2> exponentiate(float number)
{
return (number * number);
}
.
template double <1> exponentiate(float number)
{
return number;
}


The beauty of template metaprogramming! In this case the compiler generates the recursive code and end cases based on the explicit instantiation for parameters 1 and 2.

I wanna work for Microsoft!
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
0

Share this post


Link to post
Share on other sites
That only works for Positive whole numbers, mine works for all (well, if I finished it it would have... )

"I''ve learned something today: It doesn''t matter if you''re white, or if you''re black...the only color that REALLY matters is green"
-Peter Griffin
0

Share this post


Link to post
Share on other sites
quote:
Original post by Beer Hunter
Oluseyi - That looks disturbingly similar to prolog code...



It looks exactly like template metaprogramming to me. If you haven''t seen this style before, then get used to it, as you''ll be seeing lots more of it in the future!



--
Very simple ideas lie within the reach only of complex minds.
0

Share this post


Link to post
Share on other sites
quote:
Original post by matrix2113 / Oluseyi
[Edit: It''s no fun having to scroll several pages to the right to read a post]


I still do (800x600)
0

Share this post


Link to post
Share on other sites
quote:
Original post by SabreMan
It looks exactly like template metaprogramming to me.



template double <1> exponentiate(float number) {
return number;
}
template double <2> exponentiate(float number) {
return (number * number);
}
template double exponentiate(float number) {
return exponentiate(number);
}


Power(Number, 1, Result):-
Result = Number.

Power(Number, 2, Result):-
Result = Number * Number.

Power(Number, X, Result):-
Power(Number, X-1, T),
Result = T * Number.

That''s more or less how most prolog programmers would implement it. Do you see the similarities?

quote:
Original post by SabreMan
If you haven''t seen this style before, then get used to it, as you''ll be seeing lots more of it in the future!


I made a point of how that style is very common in prolog, but you seem to believe that I''ve never seen that style before.
0

Share this post


Link to post
Share on other sites