easy c++ question
How do I do exponents? I''m working on a c++ dll to handle the lighting in my visual basic game, and I need to know how to do a exponent for some basic pythagorean theorum! Also, how do I do a square root? Although that''s not as important because I can just use an exponent of 0.5 to find it.
Thanks
-00 Dork
-00 Dork
You use the carot ''^.'' But it doesn''t work on decimal numbers.
------------------------------
Trent (ShiningKnight)
ShiningKnight Games (I had to make one up, to fit in with the rest of you
)
Project: Writing tutorials and code for my OpenGL Game Programming series
OpenGL Game Programming Tutorials
------------------------------
Trent (ShiningKnight)
ShiningKnight Games (I had to make one up, to fit in with the rest of you
![](smile.gif)
Project: Writing tutorials and code for my OpenGL Game Programming series
OpenGL Game Programming Tutorials
The ^ operator is the bitwise OR operator, not the exponent function!
Check out the math.h header (or cmath if you want to be C++ standard compliant), it contains many math functions. For example, pow(x, y) raises x to the power of y. To calculate the square root of a number, you can use sqrt(x).
HTH
Check out the math.h header (or cmath if you want to be C++ standard compliant), it contains many math functions. For example, pow(x, y) raises x to the power of y. To calculate the square root of a number, you can use sqrt(x).
HTH
Some useful C++ links:Free multiplatform ANSI C++ Standard Library implementationVisual C++ 6.0 STL fixesVisual C++ 6.0 noncompliance issuesC++ FAQ Lite
JungleJim has it right on the money.
Use the math.h/cmath pow() function, or, if you just want the practice, write your own. Make sure it''s a regular function, though, and not an overloaded operator. A lot of people (including myself) thought, "Hey, we could just overload operator^ and, voila, exponential operator." It does work, but it doesn''t have the correct associativity and operator precedence. (Kudos to C++ FAQs for pointing this out.)
---
blahpers
Use the math.h/cmath pow() function, or, if you just want the practice, write your own. Make sure it''s a regular function, though, and not an overloaded operator. A lot of people (including myself) thought, "Hey, we could just overload operator^ and, voila, exponential operator." It does work, but it doesn''t have the correct associativity and operator precedence. (Kudos to C++ FAQs for pointing this out.)
---
blahpers
---blahpers
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement