# The Industry's Foundation for High Performance Graphics

1. ## GLM math constants

Hi,

I'm new to GLM (what an awesome library btw), and can't find any math constants, which seems odd given its functional coverage.

Specifically I'm looking for just good old M_PI. I see hardwired constants all over the place, which again seems odd to me. For instance in glm::core::function::trigonometric the 'degrees' function (and all other associated trigonometric functions) defines pi in place (3.141...), like this:

Code :
```// radians
template <typename genType>
(
genType const & degrees
)
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'radians' only accept floating-point input");

const genType pi = genType(3.1415926535897932384626433832795);
return degrees * (pi / genType(180));
}```

Can anyone lead me in the right direction?

Cheers,
Shane

2. ## Re: GLM math constants

That's a good point, there is no constant provided by GLM.

Which constant would be useful for you?

3. ## Re: GLM math constants

Wouldn't the ones in math.h be useful ?

4. ## Re: GLM math constants

Useful but redundant since they're already in math.h.

Now, M_PI is not part of math.h anymore thanks to C99. So it's reasonable to define that. Though if they're using C++, then C++ standard library still includes it (I think) as part of its math.h. So you may want to check to see if it is defined first.

5. ## Re: GLM math constants

Well usually M_PI (and crew) are defined in math.h as:

Code :
```#define M_E         2.71828182845904523536028747135266250   /* e */
#define M_LOG2E     1.44269504088896340735992468100189214   /* log 2e */
#define M_LOG10E    0.434294481903251827651128918916605082  /* log 10e */
#define M_LN2       0.693147180559945309417232121458176568  /* log e2 */
#define M_LN10      2.30258509299404568401799145468436421   /* log e10 */
#define M_PI        3.14159265358979323846264338327950288   /* pi */
#define M_PI_2      1.57079632679489661923132169163975144   /* pi/2 */
#define M_PI_4      0.785398163397448309615660845819875721  /* pi/4 */
#define M_1_PI      0.318309886183790671537767526745028724  /* 1/pi */
#define M_2_PI      0.636619772367581343075535053490057448  /* 2/pi */
#define M_2_SQRTPI  1.12837916709551257389615890312154517   /* 2/sqrt(pi) */
#define M_SQRT2     1.41421356237309504880168872420969808   /* sqrt(2) */
#define M_SQRT1_2   0.707106781186547524400844362104849039  /* 1/sqrt(2) */```

However, so are many of the standard trigonometric functions:

Code :
```extern double  acos( double );
extern double  asin( double );
extern double  atan( double );
extern double  atan2( double, double );
extern double  cos( double );
extern double  sin( double );
extern double  tan( double );
extern double  acosh( double );
extern double  asinh( double );
extern double  atanh( double );
extern double  cosh( double );
extern double  sinh( double );
extern double  tanh( double );```

However, these trigonometric functions are redefined in GLM in func_trigonometric.inl, despite the fact they call the std functions. For instance, 'sin':
Code :
```    // sin
template <typename genType>
GLM_FUNC_QUALIFIER genType sin
(
genType const & angle
)
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'sin' only accept floating-point input");

return ::std::sin(angle);
}```

I guess the idea is that GLM is supposed to be a one-stop-shop for math, which is great and absolutely needed, so why not go the whole way and move over the standard constants too.

I would expect to see something like, glm::M_PI or glm::constants:i .

Basically, I would love to more or less replace [itex] and <math.h> with <gml.h> and be done with it.

Cheers,
Shane

6. ## Re: GLM math constants

I guess the idea is that GLM is supposed to be a one-stop-shop for math
I'm fairly sure the idea is to do what GLSL does. GLSL has a function called "sin" which can take a scalar float (as well as vectors). Therefore, GLM must have a function called "sin" which takes a scalar float.

7. ## Re: GLM math constants

I have added a ticket for this:
https://sourceforge.net/apps/trac/ogl-math/ticket/94

I am not sure how this could be exposed but it could be interesting.

8. ## Re: GLM math constants

Excellent.

Thanks and fingers crossed we find some constants in GLM soonish.

Cheers,
Shane

9. ## Re: GLM math constants

True, however given PI is a fundamental mathematical constant, and used in graphics programming all the time (at least by me, but I use radians in my math), it struck me as odd that it was absent.

10. ## Re: GLM math constants

What now, can I found some constants in GLM?