Skip to content

Commit

Permalink
Merge pull request #268 from stillwater-sc/v3.49
Browse files Browse the repository at this point in the history
non-saturating small cfloats using a block arithmetic abstraction
  • Loading branch information
Ravenwater authored Dec 29, 2021
2 parents a2e8eff + e237bf5 commit 1efd134
Show file tree
Hide file tree
Showing 195 changed files with 25,775 additions and 9,582 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CMake

on:
push:
branches: [ main ]
branches: [ v3.49 ]
pull_request:
branches: [ main ]

Expand Down
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if(NOT DEFINED UNIVERSAL_VERSION_MAJOR)
set(UNIVERSAL_VERSION_MAJOR 3)
endif()
if(NOT DEFINED UNIVERSAL_VERSION_MINOR)
set(UNIVERSAL_VERSION_MINOR 48)
set(UNIVERSAL_VERSION_MINOR 49)
endif()
if(NOT DEFINED UNIVERSAL_VERSION_PATCH)
set(UNIVERSAL_VERSION_PATCH 1)
Expand Down Expand Up @@ -613,7 +613,7 @@ if(BUILD_NUMBER_ARITHMETIC_CLASSES)
add_subdirectory("tests/bitblock")
add_subdirectory("tests/value")
add_subdirectory("tests/blockbinary")
add_subdirectory("tests/blockfraction")
add_subdirectory("tests/blocksignificant")
add_subdirectory("tests/blocktriple")
endif(BUILD_NUMBER_ARITHMETIC_CLASSES)

Expand Down Expand Up @@ -737,11 +737,13 @@ endif(BUILD_EDUCATION)

# application examples
if(BUILD_APPLICATIONS)
add_subdirectory("applications/adaptive")
add_subdirectory("applications/approximation")
add_subdirectory("applications/blas")
add_subdirectory("applications/chaos")
add_subdirectory("applications/chebyshev")
add_subdirectory("applications/complex")
add_subdirectory("applications/constants")
add_subdirectory("applications/cryptography")
add_subdirectory("applications/dsp")
add_subdirectory("applications/engineering")
Expand All @@ -755,7 +757,7 @@ add_subdirectory("applications/roots")
add_subdirectory("applications/science")
add_subdirectory("applications/sequences")
add_subdirectory("applications/stl")
add_subdirectory("applications/trigonometry")
add_subdirectory("applications/stream")
add_subdirectory("applications/weather")
endif(BUILD_APPLICATIONS)

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ RUN cmake -DBUILD_ALL=ON .. && make
# the command 'make test' is run as part of the CI test pipeline of the release container

# add a command that when you run the container without a command, it produces something meaningful
CMD ["echo", "Universal Numbers Library Builder Version 3.48.1"]
CMD ["echo", "Universal Numbers Library Builder Version 3.49.1"]


# RELEASE stage
Expand Down Expand Up @@ -110,4 +110,4 @@ WORKDIR /home/stillwater/universal/build

# the command 'make test' is run as part of the CI test pipeline of this release container

CMD ["echo", "Universal Numbers Library Version 3.48.1"]
CMD ["echo", "Universal Numbers Library Version 3.49.1"]
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Universal: a header-only C++ template library for universal number arithmetic

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/25452f0319d34bc2a553cd1857d7dfae)](https://app.codacy.com/gh/stillwater-sc/universal?utm_source=github.com&utm_medium=referral&utm_content=stillwater-sc/universal&utm_campaign=Badge_Grade_Dashboard)
[![Awesome Cpp](https://awesome.re/mentioned-badge.svg)](https://github.com/fffaraz/awesome-cpp#math)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fstillwater-sc%2Funiversal.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fstillwater-sc%2Funiversal?ref=badge_shield)
[ ![Codeship Status for stillwater-sc/universal](https://app.codeship.com/projects/22533f00-252a-0136-2ba6-6657a5454f61/status?branch=master)](https://app.codeship.com/projects/286490)
[![Coverage Status](https://coveralls.io/repos/github/stillwater-sc/universal/badge.svg?branch=master)](https://coveralls.io/github/stillwater-sc/universal?branch=master)

| **System** | **Status** | **More information** |
|------------|------------|----------------------|
| [Codeship](https://app.codeship.com/projects/286490) | ![Codeship Status for stillwater-sc/universal](https://app.codeship.com/projects/22533f00-252a-0136-2ba6-6657a5454f61/status?branch=master) | Docker container build |
| [GitHub Actions](https://github.com/stillwater-sc/universal/actions) | [![Build Status](https://github.com/stillwater-sc/universal/actions/workflows/cmake.yml/badge.svg?branch=main)](https://github.com/stillwater-sc/universal) | Latest Linux/MacOS/Windows |
| [Codacy Code Quality](https://app.codacy.com/gh/stillwater-sc/universal/dashboard) | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/25452f0319d34bc2a553cd1857d7dfae)](https://app.codacy.com/gh/stillwater-sc/universal?utm_source=github.com&utm_medium=referral&utm_content=stillwater-sc/universal&utm_campaign=Badge_Grade_Dashboard) | Code Quality Assessment |
| [FOSSA Status](https://app.fossa.com/projects/git%2Bgithub.com%2Fstillwater-sc%2Funiversal) | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fstillwater-sc%2Funiversal.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fstillwater-sc%2Funiversal?ref=badge_shield) | Open-source license dependency scanner |
| [Codeship](https://app.codeship.com/projects/286490) | ![Codeship Status for stillwater-sc/universal](https://app.codeship.com/projects/22533f00-252a-0136-2ba6-6657a5454f61/status?branch=master) | Docker container build and regression |
| [GitHub Actions](https://github.com/stillwater-sc/universal/actions) | [![Build Status](https://github.com/stillwater-sc/universal/actions/workflows/cmake.yml/badge.svg?branch=main)](https://github.com/stillwater-sc/universal) | Latest Linux/MacOS/Windows builds and regression tests |
| [Code Coverage](https://coveralls.io) | [![Coverage Status](https://coveralls.io/repos/github/stillwater-sc/universal/badge.svg?branch=master)](https://coveralls.io/github/stillwater-sc/universal?branch=master) | Code coverage scanner |

[![Awesome Cpp](https://awesome.re/mentioned-badge.svg)](https://github.com/fffaraz/awesome-cpp#math)

The goal of the Universal Numbers Library is to offer applications alternatives to IEEE floating-point that are more efficient and mathematically robust.

Expand Down Expand Up @@ -383,20 +383,27 @@ Arithmetic tests 200000 randoms each

## Structure of the tree

The universal library contains a set of functional groups to deal with different number systems. In the examples shown above, we have seen the ".../universal/include/universal/posit" group and its test suite, ".../universal/tests/posit".
The universal library contains a set of functional groups to organize the development and validation of different number systems.
In the examples shown above, we have seen the ".../universal/include/universal/number/posit/posit.hpp" group and its test suite, ".../universal/tests/posit".

Here is a complete list:

### fixed-sized configurations

- *universal/number/integer* - arbitrary configuration fixed-size integer
- *universal/number/fixpnt* - arbitrary configuration fixed-size fixed-point number system
- *universal/number/areal* - arbitrary configuration fixed-size linear floating-point
- *universal/number/posit* - arbitrary configuration fixed-size posit number system
- *universal/number/valid* - arbitrary configuration fixed-size valid number system
- *universal/number/areal* - arbitrary configuration fixed-size faithful floating-point with uncertainty bit
- *universal/number/cfloat* - arbitrary configuration fixed-size classic floating-point number system
- *universal/number/posit* - arbitrary configuration fixed-size posit number system, a tapered floating-point
- *universal/number/valid* - arbitrary configuration fixed-size valid number system, a tapered floating-point interval number system
- *universal/number/quire* - arbitrary configuration fixed-size super accumulator number system (add/sub/abs/sqrt)
- *universal/number/unum* - flexible configuration unum Type 1 number system
- *universal/number/unum2* - flexible configuration unum Type 2 number system
- *universal/number/lns* - logarithmic number system
- *universal/number/float* - contains the implementation of the IEEE floating point augmentations for reproducible computation

### adaptive precision configurations

- *universal/number/decimal* - adaptive-precision decimal
- *universal/number/rational* - adaptive-precision rational number system
- *universal/number/adaptiveint* - adaptive-precision binary integer
Expand Down
3 changes: 3 additions & 0 deletions applications/adaptive/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
file (GLOB SOURCES "./*.cpp")

compile_all("true" "adaptive" "Applications/Oracles/Floating Point Arithmetic" "${SOURCES}")
65 changes: 65 additions & 0 deletions applications/adaptive/double-double.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// double-double.cpp: experiments with double-double floating-point arithmetic
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <universal/utility/directives.hpp>
#include <limits>
#include <utility>
#if (__cplusplus == 202003L) || (_MSVC_LANG == 202003L)
#include <numbers> // high-precision numbers
#endif
#include <universal/utility/number_system_properties.hpp> //minmax_range etc. for native types
#include <universal/common/numeric_limits_utility.hpp>
#include <universal/verification/performance_runner.hpp>

// select the number systems we would like to compare
#include <universal/number/fixpnt/fixpnt.hpp>
#include <universal/number/areal/areal.hpp>
#include <universal/number/cfloat/cfloat.hpp>
#include <universal/number/posit/posit.hpp>
#include <universal/number/lns/lns.hpp>

/*
Definition of FAITHFUL arithmetic
For a t-digit number a and b, and op element {+,-,*,/}, let c = a op b exactly.
Suppose x and y are consecutive t-digit floating-point numbers with the same
sign as c such at |x| <= |c| < |y|. Then the floating-point arithmetic is
called faithful if fl(a op b) = x whenever c = x and fl(a op b) is either x or y
whenever c != x.
*/

int main()
try {
using namespace sw::universal;

std::cout << "Experiments with double-double floating-point arithmetic\n";

std::streamsize precision = std::cout.precision();

std::cout << std::setprecision(precision);
std::cout << std::endl;

return EXIT_SUCCESS;
}
catch (char const* msg) {
std::cerr << "Caught ad-hoc exception: " << msg << std::endl;
return EXIT_FAILURE;
}
catch (const sw::universal::universal_arithmetic_exception& err) {
std::cerr << "Caught unexpected universal arithmetic exception: " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (const sw::universal::universal_internal_exception& err) {
std::cerr << "Caught unexpected universal internal exception: " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (std::runtime_error& err) {
std::cerr << "Caught unexpected runtime error: " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (...) {
std::cerr << "Caught unknown exception" << std::endl;
return EXIT_FAILURE;
}
173 changes: 173 additions & 0 deletions applications/adaptive/priest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
// priest.cpp: experiments with Douglas Priest arbitrary precision floating-point arithmetic
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <universal/utility/directives.hpp>
#include <limits>
#include <utility>
#if (__cplusplus == 202003L) || (_MSVC_LANG == 202003L)
#include <numbers> // high-precision numbers
#endif
#include <universal/utility/number_system_properties.hpp> //minmax_range etc. for native types
#include <universal/common/numeric_limits_utility.hpp>
#include <universal/verification/performance_runner.hpp>

// select the number systems we would like to compare
#include <universal/number/fixpnt/fixpnt.hpp>
#include <universal/number/areal/areal.hpp>
#include <universal/number/cfloat/cfloat.hpp>
#include <universal/number/posit/posit.hpp>
#include <universal/number/lns/lns.hpp>

/*
Definition of FAITHFUL arithmetic
For a t-digit number a and b, and op element {+,-,*,/}, let c = a op b exactly.
Suppose x and y are consecutive t-digit floating-point numbers with the same
sign as c such at |x| <= |c| < |y|. Then the floating-point arithmetic is
called faithful if fl(a op b) = x whenever c = x and fl(a op b) is either x or y
whenever c != x.
*/

template<typename Real>
std::pair<Real, Real> SumErr(Real a, Real b) {
Real c, d, e, f, g, h;

if (abs(a) < abs(b)) std::swap(a, b);
c = a + b;
e = c - a;
g = c - e;
h = g - a;
f = b - h;
d = f - e;
if (d + e != f) {
c = a, d = b;
}
return std::pair(c, d);
}

template<typename Real>
std::pair<Real, Real> SumErrCorollary2(Real a, Real b) {
Real c, d, e;

if (abs(a) < abs(b)) std::swap(a, b);
c = a + b;
e = c - a;
d = b - e;

return std::pair(c, d);
}

template<typename Real>
void TestSumErr() {
using namespace sw::universal;
using Float = sw::universal::cfloat<32, 8, uint32_t>;
Float fa, fb;
Real a, b, c, d;

fa = 1.0f;
++fa;
fb = 1.0f;
--fb;
a = float(fa);
b = float(fb);
auto result = SumErr(a, b);
c = result.first;
d = result.second;
std::cout << c << " + " << d << " = " << a << " + " << b << '\n';
std::cout << to_binary(c) << " : " << to_binary(a + b) << '\n';
std::cout << to_binary(d) << '\n';
std::cout << "a : " << to_binary(a) << '\n';
std::cout << "b : " << to_binary(b) << '\n';
std::cout << "c : " << to_binary(c) << '\n';
std::cout << "d : " << to_binary(d) << '\n';

std::cout << "Corollary2: simplified\n";
result = SumErrCorollary2(a, b);
c = result.first;
d = result.second;
std::cout << c << " + " << d << " = " << a << " + " << b << '\n';
std::cout << to_binary(c) << " : " << to_binary(a + b) << '\n';
std::cout << to_binary(d) << '\n';
std::cout << "a : " << to_binary(a) << '\n';
std::cout << "b : " << to_binary(b) << '\n';
std::cout << "c : " << to_binary(c) << '\n';
std::cout << "d : " << to_binary(d) << '\n';
}

template<typename Real>
std::pair<Real, Real> split(Real x, unsigned k) {
using namespace sw::universal;
unsigned t = ieee754_parameter<Real>::fbits;
Real a_k = static_cast<Real>((1ull << (t - k)) + 1);
Real y = a_k * x;
Real z = y - x;
Real xp = y - z;
Real xpp = x - xp;
return std::pair(xp, xpp);
}

int main()
try {
using namespace sw::universal;

std::cout << "Douglas Priest arbitrary precision arithmetic experiments\n";

using Sngle = float;
using Longd = long double;
using Fixed = fixpnt<32,16>;
using Posit = posit<32,2>;
using Float = cfloat<32, 8, uint32_t>;
using Areal = areal<32, 8, uint32_t>;
using Lns = lns<32, uint32_t>;


std::streamsize precision = std::cout.precision();
std::cout << std::setprecision(std::numeric_limits<Longd>::max_digits10);
std::cout << "float digits of precision : " << std::numeric_limits<float>::max_digits10 << '\n';
std::cout << "double digits of precision : " << std::numeric_limits<double>::max_digits10 << '\n';
std::cout << "long double digits of precision : " << std::numeric_limits<Longd>::max_digits10 << '\n';

TestSumErr<float>();
TestSumErr<double>();

std::cout << "\nSplitting of a floating-point value\n";
Float fa{ 1.875f + 0.0625f + 0.03125f };
++fa;
float x = float(fa);
for (unsigned k = 1; k < 10; ++k) {
auto xs = split(x, k);
float xp = xs.first;
float xpp = xs.second;
std::cout << "x : " << to_binary(x) << " : " << x << '\n';
std::cout << "x' : " << to_binary(xp) << " : " << xp << '\n';
std::cout << "x'' : " << to_binary(xpp) << " : " << xpp << '\n';
}


std::cout << std::setprecision(precision);
std::cout << std::endl;

return EXIT_SUCCESS;
}
catch (char const* msg) {
std::cerr << "Caught ad-hoc exception: " << msg << std::endl;
return EXIT_FAILURE;
}
catch (const sw::universal::universal_arithmetic_exception& err) {
std::cerr << "Caught unexpected universal arithmetic exception: " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (const sw::universal::universal_internal_exception& err) {
std::cerr << "Caught unexpected universal internal exception: " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (std::runtime_error& err) {
std::cerr << "Caught unexpected runtime error: " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (...) {
std::cerr << "Caught unknown exception" << std::endl;
return EXIT_FAILURE;
}
8 changes: 4 additions & 4 deletions applications/approximation/taylor_series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ try {
return EXIT_SUCCESS;
}
catch (char const* msg) {
std::cerr << msg << std::endl;
std::cerr << "Caught ad-hoc exception: " << msg << std::endl;
return EXIT_FAILURE;
}
catch (const sw::universal::universal_arithmetic_exception& err) {
std::cerr << "Caught an unexpected universal arithmetic exception: " << err.what() << std::endl;
std::cerr << "Caught unexpected universal arithmetic exception: " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (const sw::universal::universal_internal_exception& err) {
std::cerr << "Caught an unexpected universal internal exception: " << err.what() << std::endl;
std::cerr << "Caught unexpected universal internal exception: " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (std::runtime_error& err) {
std::cerr << "Caught an unexpected runtime exception: " << err.what() << std::endl;
std::cerr << "Caught unexpected runtime error: " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (...) {
Expand Down
2 changes: 1 addition & 1 deletion applications/blas/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
file (GLOB SOURCES "./*.cpp")

compile_all("true" "blas" "Applications/Basic Linear Algebra" "${SOURCES}")
compile_all("true" "blas" "Applications/Reproducibility/Basic Linear Algebra" "${SOURCES}")
Loading

0 comments on commit 1efd134

Please sign in to comment.