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

sqrt calculates incorrectly with elastic_fixed_point #85

Closed
hbe72 opened this issue Dec 20, 2017 · 1 comment
Closed

sqrt calculates incorrectly with elastic_fixed_point #85

hbe72 opened this issue Dec 20, 2017 · 1 comment
Assignees
Labels

Comments

@hbe72
Copy link
Collaborator

hbe72 commented Dec 20, 2017

Simple test to copy paste to test/fixed_point/extras.cpp

using cnl::fixed_point;
using cnl::elastic_fixed_point;
//cnl::sqrt
TEST(utils_tests, sqrt)
{
    EXPECT_FLOAT_EQ(static_cast<float>(sqrt(fixed_point<cnl::int32, -20>(0))), 0.0f);
    EXPECT_FLOAT_EQ(static_cast<float>(sqrt(fixed_point<cnl::int32, -20>(2.0))), 1.414213562373095f);
    EXPECT_FLOAT_EQ(static_cast<float>(sqrt(fixed_point<cnl::int32, -20>(4.0))), 2.0f);
    EXPECT_FLOAT_EQ(static_cast<float>(sqrt(elastic_fixed_point<32, -20>(0))), 0.0f);
    EXPECT_FLOAT_EQ(static_cast<float>(sqrt(elastic_fixed_point<32, -20>(2.0))), 1.414213562373095f);
    EXPECT_FLOAT_EQ(static_cast<float>(sqrt(elastic_fixed_point<32, -20>(4.0))), 2.0f);
}

Fails with

<path>/cnl/cmake-build-debug/src/test/fp_test --gtest_filter=* --gtest_color=no
<path>/cnl/src/test/fixed_point/extras.cpp:55: Failure
Expected equality of these values:
  static_cast<float>(sqrt(elastic_fixed_point<32, -20>(2.0)))
    Which is: 2
  1.414213562373095f
    Which is: 1.4142135

<path>/cnl/src/test/fixed_point/extras.cpp:56: Failure
Expected equality of these values:
  static_cast<float>(sqrt(elastic_fixed_point<32, -20>(4.0)))
    Which is: 2.8284264
  2.0f
    Which is: 2
@hbe72 hbe72 added the bug label Dec 20, 2017
johnmcfarlane pushed a commit that referenced this issue Dec 21, 2017
johnmcfarlane pushed a commit that referenced this issue Dec 21, 2017
@johnmcfarlane johnmcfarlane self-assigned this Dec 21, 2017
johnmcfarlane pushed a commit that referenced this issue Dec 21, 2017
johnmcfarlane pushed a commit that referenced this issue Dec 21, 2017
johnmcfarlane pushed a commit that referenced this issue Dec 21, 2017
@johnmcfarlane
Copy link
Owner

Thanks!

troian pushed a commit to notifai/cnl that referenced this issue May 6, 2021
troian pushed a commit to notifai/cnl that referenced this issue May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants