Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5937175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:30:07+00:00 2026-05-22T15:30:07+00:00

I am creating a helper namespace for one of my projects, i wanted it

  • 0

I am creating a helper namespace for one of my projects, i wanted it to be able to use all types like ints, floats, doubles etc. But it seems like i just cant get the templating right.

Anyways, here is my current code, my compiler doesn’t spit out errors about the file itself, though when i compile it it spits out hundreds of errors in other files.
These errors aren’t there when i remove the templating in the file:

#include "..\util\Logger.hpp"

namespace gm
{
    namespace math
    {
        namespace MathHelper
        {
            // Value of Pi
            const double PI = 3.1415926535897932384626433832795028841972;
            // Value of euler
            const double E =  2.7182818284590452353602874713526624977572;

            // Convert radians to degrees
            template <typename T>
            T Rad2Deg(T angle)
            {
                return angle * (180 / (T)PI);
            }

            // Convert degrees to radians
            template <typename T>
            T Deg2Rad(T angle)
            {
                return angle * ((T)PI / 180);
            }

            // Clamp a value in between the given min and max
            template <typename T>
            T Clamp(T value, T min, T max)
            {
                if(min > max) { gm::util::Logger::DisplayError("Invalid argument in MathHelper::Clamp, max is over min"); }
                if(value < min) { value = min; }
                if(value > max) { value = max; }
                return value;
            }

            // Exponentiate value a with value b
            template <typename T>
            T Exp(T a, int b)
            {
                if(b < 0) { gm::util::Logger::DisplayError("Invalid argument in MathHelper::Exp, b must be positive"); }
                T value = a;
                for(int i = 1; i < b; i++) { value *= a; }
                return value;
            }

            // Get the absolute value of the value passed
            template <typename T>
            T Abs(T a, T b)
            {
                if(value < 0) { value = -value;
                return value;
            }
        };
    };
};

I put the compile errors in this paste: http://pastebin.com/AxwmDyDh

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:30:08+00:00Added an answer on May 22, 2026 at 3:30 pm

    Your deg/rad conversion functions won’t work right if you pass in an int for T because PI will get truncated to int before doing the conversion. I can’t quite make out why you have that in there.

    Using variable names like min and max will cause problems if you have a using namespace anywhere.

    Your abs function is missing a closing } on the if. That could cause errors at the call point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I decided to use the singleton design pattern while creating a view helper class.
I've created several helper functions which I use when creating templates for Wordpress. An
Creating MVC3 Razor Helper like Helper.BeginForm() says that it can be done using extension
I'm creating a DirectX 11 helper class that looks kind of like this: #import
I am in the proces of creating a helper method that will allow me
When creating gems, I often have a directory structure like this: |--lib |-- helpers.rb
Creating a server-side socket will fail if I'm trying to use the same port
In Python, it is possible to nest functions like this: def do_something(): def helper():
Am creating an action helper that will require the return value of the Zend_View_Helper_BaseUrl
I have been looking at creating a synchroniser helper template class which is based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.