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

Error: isEqual #128

Open
yanminhui opened this issue Jan 16, 2024 · 0 comments
Open

Error: isEqual #128

yanminhui opened this issue Jan 16, 2024 · 0 comments

Comments

@yanminhui
Copy link

bool isEqual(const double first, const double second, const double epsilon = 1e-6)
{
return abs(first - second) < epsilon;
}

cppinsights:

bool isEqual(const double first, const double second, const double epsilon)
{
  return static_cast<double>(abs(static_cast<int>(first - second))) < epsilon;
}

first-second 转换为 int 已经失去精确度。

Example: https://compiler-explorer.com/z/TPrcsGbEE

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

1 participant