-
-
Notifications
You must be signed in to change notification settings - Fork 60
How to use
Theodore Omtzigt edited this page Aug 7, 2024
·
8 revisions
The Universal library provides a low-friction environment to start exploring alternatives to IEEE floating-point in numerical algorithms, and alternatives to integers for crypto algorithms.
The basic use pattern is as simple as:
#include <universal/number/posit/posit.hpp>
template<typename Real>
Real MyKernel(const Real& a, const Real& b) {
return a * b; // replace this with your kernel computation
}
constexpr double pi = 3.14159265358979323846;
int main() {
using Real = sw::universal::posit<32,2>;
Real a = sqrt(2);
Real b = pi;
std::cout << "Result: " << MyKernel(a, b) << std::endl;
}
All the number systems reside in the namespace sw::universal
, and can be brought into your application by including the number system header file located in $UNIVERAL_ROOT/include/universal/number/...
universal