| 1912 | |
| 1913 | template <typename Tmpl, typename Conc> |
| 1914 | void test_bit_exact_equivalence() { |
| 1915 | // Determine test value ranges based on INT_BITS |
| 1916 | constexpr int intBits = Tmpl::INT_BITS; |
| 1917 | const float maxRange = static_cast<float>((1 << (intBits - 1)) - 1); |
| 1918 | |
| 1919 | // Select test values appropriate for the type's range |
| 1920 | float test_vals[9]; |
| 1921 | int num_vals = 0; |
| 1922 | test_vals[num_vals++] = 0.0f; |
| 1923 | test_vals[num_vals++] = 0.25f; |
| 1924 | test_vals[num_vals++] = 0.5f; |
| 1925 | test_vals[num_vals++] = 1.0f; |
| 1926 | test_vals[num_vals++] = -1.0f; |
| 1927 | if (maxRange >= 2.0f) test_vals[num_vals++] = 2.0f; |
| 1928 | if (maxRange >= 5.0f) test_vals[num_vals++] = 5.0f; |
| 1929 | if (maxRange >= 10.0f) test_vals[num_vals++] = 10.0f; |
| 1930 | if (maxRange >= 100.0f) test_vals[num_vals++] = 100.0f; |
| 1931 | |
| 1932 | // Test arithmetic operations |
| 1933 | for (int i = 0; i < num_vals; ++i) { |
| 1934 | for (int j = 0; j < num_vals; ++j) { |
| 1935 | float a_val = test_vals[i]; |
| 1936 | float b_val = test_vals[j]; |
| 1937 | Tmpl ta(a_val), tb(b_val); |
| 1938 | Conc ca(a_val), cb(b_val); |
| 1939 | |
| 1940 | FL_CHECK_EQ((ta + tb).raw(), (ca + cb).raw()); |
| 1941 | FL_CHECK_EQ((ta - tb).raw(), (ca - cb).raw()); |
| 1942 | FL_CHECK_EQ((ta * tb).raw(), (ca * cb).raw()); |
| 1943 | if (b_val != 0.0f) { |
| 1944 | FL_CHECK_EQ((ta / tb).raw(), (ca / cb).raw()); |
| 1945 | } |
| 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | // Test transcendental functions |
| 1950 | float trig_vals[] = {0.0f, 0.5f, 1.0f, 1.5708f, 3.1416f}; |
| 1951 | for (float v : trig_vals) { |
| 1952 | Tmpl tv(v); |
| 1953 | Conc cv(v); |
| 1954 | |
| 1955 | FL_CHECK_EQ(Tmpl::sin(tv).raw(), Conc::sin(cv).raw()); |
| 1956 | FL_CHECK_EQ(Tmpl::cos(tv).raw(), Conc::cos(cv).raw()); |
| 1957 | FL_CHECK_EQ(Tmpl::sqrt(tv).raw(), Conc::sqrt(cv).raw()); |
| 1958 | FL_CHECK_EQ(Tmpl::atan(tv).raw(), Conc::atan(cv).raw()); |
| 1959 | } |
| 1960 | |
| 1961 | // Test pow for s16x16 type (has sufficient range) |
| 1962 | if (intBits >= 16) { |
| 1963 | for (float v : trig_vals) { |
| 1964 | Tmpl tv(v); |
| 1965 | Conc cv(v); |
| 1966 | FL_CHECK_EQ(Tmpl::pow(tv, Tmpl(2.0f)).raw(), Conc::pow(cv, Conc(2.0f)).raw()); |
| 1967 | } |
| 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | FL_TEST_CASE("fixed_point<4,12> bit-exact vs s4x12") { |