c26451 overflow 에러

조회수 1376회

Vector2(float _x = 0.0f, float _y = 0.0f) : x(_x), y(_y) {}

float Magnitude() { return (float)sqrt(x * x + y * y); }

return에서 overflow 에러났는데, 왜 문제인지, 어떻게 고쳐야하는지 모르겠어요.

  • (•́ ✖ •̀)
    알 수 없는 사용자

1 답변

  • 돌려 봤는데 에러 안나는데요?

    • 코드
    #include <iostream>
    
    using namespace std;
    
    class Vector2
    {
    public:
        Vector2(float _x = 0.0f, float _y = 0.0f) : x(_x), y(_y) {}
        float Magnitude() { return (float)sqrt(x * x + y * y); }
    private:
        float x{ 0 };
        float y{ 0 };
    };
    
    int main()
    {
        Vector2 a;
        Vector2 b{ 3,-3 };
        Vector2 c{ numeric_limits<float>::max(),numeric_limits<float>::max() };
    
        cout << a.Magnitude() << '\n';
        cout << b.Magnitude() << '\n';
        cout << c.Magnitude() << '\n';
    }
    
    • 결과

    이미지

    • (•́ ✖ •̀)
      알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)