//==================================================================================================
/**
  EVE - Expressive Vector Engine
  Copyright : EVE Project Contributors
  SPDX-License-Identifier: BSL-1.0
**/
//==================================================================================================
#include "test.hpp"
#include <eve/module/core.hpp>
#include <eve/module/math.hpp>
#include <cmath>
#include <iomanip>

//==================================================================================================
// Types tests
//==================================================================================================
TTS_CASE_TPL( "Check return types of invsqrt_2"
            , eve::test::simd::ieee_reals
            )
<typename T>(tts::type<T>)
{
  using v_t = eve::element_type_t<T>;
  using eve::as;

  TTS_EXPR_IS( eve::invsqrt_2(as<T>())  , T);
  TTS_EXPR_IS( eve::invsqrt_2(as<v_t>()), v_t);
};

//==================================================================================================
// invsqrt_2  tests
//==================================================================================================
TTS_CASE_TPL( "Check behavior of invsqrt_2 on wide"
        , eve::test::simd::ieee_reals
        )
<typename T>(tts::type<T>)
{
  using eve::as;
  using eve::downward;
  using eve::upward;
  std::cout << (eve::invsqrt_2(as<float>()) <  1.0l/(std::sqrt(2.0l))) << std::endl;
  std::cout << (eve::invsqrt_2(as<double>()) < 1.0l/(std::sqrt(2.0l))) << std::endl;
  TTS_ULP_EQUAL(eve::invsqrt_2(as<T>()), T(1.0/(4.0*std::sqrt(2.0))), 0.0);
  TTS_EXPECT(eve::all(downward(eve::invsqrt_2)(as<T>()) <= eve::invsqrt_2(as<T>())));
  TTS_EXPECT(eve::all(eve::invsqrt_2(as<T>()) <= upward(eve::invsqrt_2)(as<T>())));
};
