Skip to content

Commit

Permalink
adding a math library to the posito oracle so we can use it to compar…
Browse files Browse the repository at this point in the history
…e native implementations
  • Loading branch information
Ravenwater committed Dec 24, 2023
1 parent b698230 commit 3ec54ad
Show file tree
Hide file tree
Showing 55 changed files with 1,140 additions and 175 deletions.
2 changes: 1 addition & 1 deletion include/universal/number/posit/attributes.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// attributes.hpp: functions to query number system attributes
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/exceptions.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// exceptions.hpp: exception hierarchy for exceptions during posit calculations
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <universal/common/exceptions.hpp>
Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/exponent.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// exponent.hpp: definition of a posit exponent
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/fdp.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// fdp.hpp : include file containing templated C++ interfaces to fused dot product
//
// Copyright (C) 2017-2023 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/fraction.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// fraction.hpp: definition of a posit fractions
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/manipulators.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// manipulators.hpp: definitions of helper functions for posit type manipulation
//
// Copyright (C) 2017-2023 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/math/classify.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// math_classify.hpp: classification functions for posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/math/complex.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// complex.hpp: functions for complex posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <complex>
Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/math/error_and_gamma.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// error_gamma.hpp: error and gamma functions for posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/math/exponent.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// exponent.hpp: exponent functions for posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/math/fractional.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// math_frac.hpp: fractional functions for posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/math/hyperbolic.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// hyperbolic.hpp: hyperbolic functions for posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/math/hypot.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// hypot.hpp: hypotenuse functions for posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/math/logarithm.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// logarithm.hpp: logarithm functions for posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/math/minmax.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// math_minmax.hpp: min/max functions for posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/math/next.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// math_next.hpp: nextafter/nexttoward functions for posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/math/pow.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// pow.hpp: pow functions for posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/math/sqrt.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// sqrt.hpp: sqrt functions for posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <universal/native/ieee754.hpp>
Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/math/sqrt_tables.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// sqrt_tables.hpp: specialized posit configurations to support efficient sqrt for small posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/math/trigonometry.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// trigonometric.hpp: trigonometric functions for posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <universal/math/math_constants.hpp> // for m_pi_2
Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/math/truncate.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// truncate.hpp: truncation functions (trunc, round, floor, and ceil) for posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/mathlib.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// mathlib.hpp: elementary functions for the posit number system
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/numeric_limits.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// numeric_limits.hpp: definition of numeric_limits for posit types
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/posit_c_api.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// posit_c_api.h: generic C API defining the posit api
//
// Copyright (C) 2017-2019 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/posit_fwd.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// posit_fwd.hpp : forward declarations of the posit/quire environment
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/posit_impl.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// posit_impl.hpp: implementation of arbitrary configuration fixed-size posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <cmath>
Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/posit_parse.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// posit_parse.hpp: parsing a posit in posit format
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/quire.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// quire.hpp: definition of a parameterized quire configurations for posits
//
// Copyright (C) 2017-2023 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <universal/utility/boolean_logic_operators.hpp>
Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/table.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// table.hpp: generate a table of encoding and values for fixed-size arbitrary configuration posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/posit/twoSum.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// twoSum.hpp : TwoSum specialization for posit number systems
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
6 changes: 6 additions & 0 deletions include/universal/number/posito/attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ namespace sw { namespace universal {

using namespace sw::universal::internal;

// get the sign of the posito
template<unsigned nbits, unsigned es>
constexpr inline bool sign(const posito<nbits, es>& p) {
return p.isneg();
}

// calculate the scale of a posit
template<unsigned nbits, unsigned es>
inline int scale(const posito<nbits, es>& p) {
Expand Down
54 changes: 54 additions & 0 deletions include/universal/number/posito/math/classify.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma once
// math_classify.hpp: classification functions for positos
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

namespace sw { namespace universal {

// the current shims are NON-COMPLIANT with the posito standard, which says that every function must be
// correctly rounded for every input value. Anything less sacrifices bitwise reproducibility of results.

// STD LIB function for IEEE floats: Categorizes floating point value arg into the following categories: zero, subnormal, normal, infinite, NAN, or implementation-defined category.
template<unsigned nbits, unsigned es>
int fpclassify(const posito<nbits,es>& p) {
return std::fpclassify((long double)(p));
}

// STD LIB function for IEEE floats: Determines if the given floating point number arg has finite value i.e. it is normal, subnormal or zero, but not infinite or NaN.
// specialized for positos
template<unsigned nbits, unsigned es>
inline bool isfinite(const posito<nbits,es>& p) {
return !p.isnar();
}

// STD LIB function for IEEE floats: Determines if the given floating point number arg is a positoive or negative infinity.
// specialized for positos
template<unsigned nbits, unsigned es>
inline bool isinf(const posito<nbits, es>& p) {
return p.isnar();
}

// STD LIB function for IEEE floats: Determines if the given floating point number arg is a not-a-number (NaN) value.
// specialized for positos
template<unsigned nbits, unsigned es>
inline bool isnan(const posito<nbits, es>& p) {
return p.isnar();
}

// STD LIB function for IEEE floats: Determines if the given floating point number arg is normal, i.e. is neither zero, subnormal, infinite, nor NaN.
// specialized for positos
template<unsigned nbits, unsigned es>
inline bool isnormal(const posito<nbits, es>& p) {
return std::isnormal((long double)(p));
}

// STD LIB function for IEEE floats: Determines if the given floating point number arg is normal, i.e. is neither zero, subnormal, infinite, nor NaN.
// specialized for positos
template<unsigned nbits, unsigned es>
inline bool isdenorm(const posito<nbits, es>& p) {
return (p.isnar() ? false : false); // positos are never denormalized
}

}} // namespace sw::universal
32 changes: 32 additions & 0 deletions include/universal/number/posito/math/complex.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once
// complex.hpp: functions for complex positos
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <complex>

namespace sw { namespace universal {

// the current shims are NON-COMPLIANT with the posito standard, which says that every function must be
// correctly rounded for every input value. Anything less sacrifices bitwise reproducibility of results.

// Real component of a complex posito
template<unsigned nbits, unsigned es>
posito<nbits,es> real(std::complex< posito<nbits,es> > x) {
return posito<nbits,es>(x.real());
}

// Imaginary component of a complex posito
template<unsigned nbits, unsigned es>
posito<nbits,es> imag(std::complex< posito<nbits,es> > x) {
return posito<nbits,es>(x.imag());
}

// Conjucate of a complex posito
template<unsigned nbits, unsigned es>
std::complex< posito<nbits,es> > conj(std::complex< posito<nbits,es> > x) {
return std::complex< posito<nbits,es> >(x.real(), -x.imag());
}

}} // namespace sw::universal
25 changes: 25 additions & 0 deletions include/universal/number/posito/math/error_and_gamma.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
// error_gamma.hpp: error and gamma functions for positos
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

namespace sw { namespace universal {

// the current shims are NON-COMPLIANT with the posito standard, which says that every function must be
// correctly rounded for every input value. Anything less sacrifices bitwise reproducibility of results.

// Compute the error function erf(x) = 2 over sqrt(PI) times Integral from 0 to x of e ^ (-t)^2 dt
template<unsigned nbits, unsigned es>
posito<nbits,es> erf(posito<nbits,es> x) {
return posito<nbits,es>(std::erf(double(x)));
}

// Compute the complementary error function: 1 - erf(x)
template<unsigned nbits, unsigned es>
posito<nbits,es> erfc(posito<nbits,es> x) {
return posito<nbits,es>(std::erfc(double(x)));
}

}} // namespace sw::universal
Loading

0 comments on commit 3ec54ad

Please sign in to comment.