sqrt.cpp (1219B)
1 /** 2 * KFR (https://www.kfrlib.com) 3 * Copyright (C) 2016-2023 Dan Cazarin 4 * See LICENSE.txt for details 5 */ 6 7 #include <kfr/testo/testo.hpp> 8 9 #include <kfr/math/sqrt.hpp> 10 11 using namespace kfr; 12 13 namespace CMT_ARCH_NAME 14 { 15 16 TEST(intrin_sqrt) 17 { 18 testo::assert_is_same<decltype(kfr::sqrt(9)), fbase>(); 19 testo::assert_is_same<decltype(kfr::intrinsics::sqrt(9)), fbase>(); 20 testo::assert_is_same<decltype(kfr::sqrt(make_vector(9))), vec<fbase, 1>>(); 21 testo::assert_is_same<decltype(kfr::sqrt(make_vector(9, 25))), vec<fbase, 2>>(); 22 CHECK(kfr::sqrt(9) == fbase(3.0)); 23 CHECK(kfr::sqrt(2) == fbase(1.4142135623730950488)); 24 CHECK(kfr::sqrt(-9) == fbase(qnan)); 25 CHECK(kfr::sqrt(make_vector(9)) == make_vector<fbase>(3.0)); 26 CHECK(kfr::sqrt(make_vector(-9)) == make_vector<fbase>(qnan)); 27 testo::matrix(named("type") = float_vector_types<vec>, named("value") = std::vector<int>{ 0, 2, 65536 }, 28 [](auto type, int value) 29 { 30 using T = typename decltype(type)::type; 31 const T x(value); 32 CHECK(kfr::sqrt(x) == apply([](auto x) -> decltype(x) { return std::sqrt(x); }, x)); 33 }); 34 } 35 36 37 }