0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-11 14:38:57 +02:00

ircd::math: Add difference template convenience.

This commit is contained in:
Jason Volk 2022-11-23 17:04:05 +00:00
parent 47e54547f9
commit a53963fc51
2 changed files with 49 additions and 0 deletions

48
include/ircd/math/diff.h Normal file
View file

@ -0,0 +1,48 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2022 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_MATH_DIFF_H
namespace ircd::math
{
template<class T>
typename std::enable_if<!simd::is<T>(), T>::type
diff(const T, const T);
template<class T>
typename std::enable_if<simd::is<T>(), T>::type
diff(const T, const T);
}
namespace ircd
{
using math::diff;
}
template<class T>
inline typename std::enable_if<ircd::simd::is<T>(), T>::type
ircd::math::diff(const T a, const T b)
{
T r;
for(uint i(0); i < simd::lanes<T>(); ++i)
r[i] = diff(a[i], b[i]);
return r;
}
template<class T>
inline typename std::enable_if<!ircd::simd::is<T>(), T>::type
ircd::math::diff(const T a, const T b)
{
return a > b?
a - b:
b - a;
}

View file

@ -12,6 +12,7 @@
#define HAVE_IRCD_MATH_MATH_H
#include "log2.h"
#include "diff.h"
#include "inv.h"
#include "mean.h"
#include "tanh.h"