Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How Approx handle INF #612

Closed
DarwinSenior opened this issue Mar 15, 2016 · 4 comments
Closed

How Approx handle INF #612

DarwinSenior opened this issue Mar 15, 2016 · 4 comments

Comments

@DarwinSenior
Copy link

So, I have a question regarding to Approx(INF), it seems that REQUIRE(Approx(INF) == INF) is false if I use float INF = std::numeric_limits<float>::infinity().

here is what I got

/Users/DarwinSenior/Desktop/cs419/tracer2/test/misc.cc:13: FAILED:
  REQUIRE( INF == Approx(INF) )
with expansion:
  inff == Approx( inf )

And my test case file

#include "catch.hpp"
#include <iostream>
#include <limits>

using namespace std;

namespace{
    float INF = std::numeric_limits<float>::infinity();

}

TEST_CASE("MISC", "[MISC]"){
    REQUIRE(INF == Approx(INF));
}

So, is there any way I could use Approx along with INF?

@lightmare
Copy link
Contributor

Mathematically, Approx(inf) doesn't make sense. No finite number is "close enough" to infinity.

If you want to check that x is so large that adding something to it would overflow, resulting in +infinity, there's std::numeric_limits<float>::max().

CHECK(x >= std::numeric_limits<float>::max())

It's probably safe to use Approx with float max (not with double max, as that might overflow in operator==(double, Approx)). Although I still don't see the point, Approx is intended to check that calculation results are within a margin of error; not that they're (close to) overflowing.

@horenmar
Copy link
Member

Why exactly do you want to have Approx of infinity?

@DarwinSenior
Copy link
Author

That was long time ago for the course project when I decided to write test case for ray tracing. Using infinity for the the parallel cases. I will close this issue.

@horenmar
Copy link
Member

Ok. I am not categorically opposed to making Approx infinity aware (although it would most likely start as "hey, don't do that" error on construction), but I wanted to know the motivation to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants