Skip to content

Commit

Permalink
header updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Aug 24, 2024
1 parent 679b788 commit 6a77dd9
Show file tree
Hide file tree
Showing 25 changed files with 251 additions and 108 deletions.
2 changes: 1 addition & 1 deletion include/universal/math/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
|---------------|-------------|
| abs ( ) | absolute value of an integer. The absolute value of a number is always positive. Only integer values are supported in C. |
| floor ( ) | nearest integer which is less than or equal to the argument passed to this function. |
| round ( ) | nearest integer value of the float/double/long double argument passed to this function. If decimal value is from “.1 to .5”, it returns integer value less than the argument. If decimal value is from “.6 to .9”, it returns the integer value greater than the argument. |
| ceil ( ) | return nearest integer value which is greater than or equal to the argument passed to this function. |
| round ( ) | nearest integer value of the float/double/long double argument passed to this function. If decimal value is from “.1 to .5”, it returns integer value less than the argument. If decimal value is from “.6 to .9”, it returns the integer value greater than the argument. |
| sin ( ) | return sine value. |
| cos ( ) | return cosine. |
| cosh ( ) | return hyperbolic cosine. |
Expand Down
1 change: 1 addition & 0 deletions include/universal/math/math_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// math_constants.hpp: definition of math constants
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
3 changes: 2 additions & 1 deletion include/universal/math/math_functions.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
// math_functions.hpp: definition of universal mathematical functions
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// <universal/math/math>: standard header of the universal math library shim layer
// which injects the standard math library functions for native IEEE-754 types into the sw::universal namespace.
// <universal/math/mathlib.hpp>: standard header of the universal math library shim layer
// which injects the standard math library functions for native IEEE-754 types into
// the sw::universal namespace.
//
// For example, std::abs(float) is shimmed to
// template<typename NativeFloat> sw::universal::abs(NativeFloat)
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#ifndef _UNIVERSAL_MATH_STANDARD_HEADER_
#define _UNIVERSAL_MATH_STANDARD_HEADER_
#ifndef _UNIVERSAL_MATHLIB_STANDARD_HEADER_
#define _UNIVERSAL_MATHLIB_STANDARD_HEADER_

////////////////////////////////////////////////////////////////////////////////////////
/// BEHAVIORAL COMPILATION SWITCHES
Expand Down
3 changes: 2 additions & 1 deletion include/universal/math/stub/abs.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
// abs.hpp: templated abs function stub for native floating-point
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
27 changes: 0 additions & 27 deletions include/universal/math/stub/classify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,6 @@ namespace sw { namespace universal {
#elif defined(_MSC_VER)
/* Microsoft Visual Studio. --------------------------------- */

// 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<typename Scalar,
typename = typename std::enable_if<std::is_floating_point<Scalar>::value, Scalar>::type>
int fpclassify(const Scalar& v) {
return std::fpclassify(v);
}

// STD LIB function for IEEE floats:
template<typename Scalar,
typename = typename std::enable_if<std::is_floating_point<Scalar>::value, Scalar>::type>
inline bool isfinite(const Scalar& v) {
return !std::isnan(v) && !std::isinf(v);
}

#elif defined(__PGI)
/* Portland Group PGCC/PGCPP. ------------------------------- */
Expand All @@ -92,18 +79,4 @@ namespace sw { namespace universal {
#endif


// Universal function supported by all number systems

template<typename Scalar,
typename = typename std::enable_if<std::is_floating_point<Scalar>::value, Scalar>::type>
inline bool isdenorm(const Scalar& v) {
return !std::isnormal(v) && !std::isnan(v) && !std::isinf(v);
}

// define an alias issubnorm for isdenorm
template<typename Scalar,
typename = typename std::enable_if<std::is_floating_point<Scalar>::value, Scalar>::type>
inline bool issubnorm(const Scalar& v) { return isdenorm(v); }


}} // namespace sw::universal
3 changes: 2 additions & 1 deletion include/universal/math/stub/complex.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
// complex.hpp: templated complex functions stubs for native floating-point
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <complex>
Expand Down
3 changes: 2 additions & 1 deletion include/universal/math/stub/error_and_gamma.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
// error_gamma.hpp: templated error and gamma function stubs for native floating-point
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
3 changes: 2 additions & 1 deletion include/universal/math/stub/exponent.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
// exponent.hpp: templated exponent function stubs for native floating-point
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
3 changes: 2 additions & 1 deletion include/universal/math/stub/fractional.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
// fractional.hpp: templated fractional function stubs for native floating-point
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
3 changes: 2 additions & 1 deletion include/universal/math/stub/hyperbolic.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
// hyperbolic.hpp: templated hyperbolic function stubs for native floating-point
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
3 changes: 2 additions & 1 deletion include/universal/math/stub/hypot.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
// hypot.hpp: templated hypotenuse function stubs for native floating-point
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
3 changes: 2 additions & 1 deletion include/universal/math/stub/logarithm.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
// logarithm.hpp: templated logarithm function stubs for native floating-point
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
3 changes: 2 additions & 1 deletion include/universal/math/stub/minmax.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
// math_minmax.hpp: templated min/max function stubs for native floating-point
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
3 changes: 2 additions & 1 deletion include/universal/math/stub/next.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
// next.hpp: templated nextafter/nexttoward function stubs for native floating-point
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
3 changes: 2 additions & 1 deletion include/universal/math/stub/pow.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
// pow.hpp: templated pow function stubs for native floating-point
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
3 changes: 2 additions & 1 deletion include/universal/math/stub/sqrt.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
// sqrt.hpp: templated sqrt function stub for native floating-point
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
3 changes: 2 additions & 1 deletion include/universal/math/stub/trigonometry.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
// trigonometric.hpp: templated trigonometric function stubs for native floating-point
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
3 changes: 2 additions & 1 deletion include/universal/math/stub/truncate.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
// truncate.hpp: templated truncation function stubs for native floating-point (trunc, round, floor, and ceil) for posits
//
// Copyright (C) 2017-2022 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

Expand Down
7 changes: 0 additions & 7 deletions include/universal/native/ieee754.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
#include <universal/native/ieee754_decoder.hpp>
#include <universal/native/ieee754_type_tag.hpp>

////////////////////////////////////////////////////////////////////////////////////////
// enable throwing specific exceptions long double special handling of 128bit fields
#if !defined(BITBLOCK_THROW_ARITHMETIC_EXCEPTION)
// default is to use std::cerr for signalling an error
#define BITBLOCK_THROW_ARITHMETIC_EXCEPTION 0
#endif

// if the compiler environment allows, set up
// constexpr compatible bit casts, otherwise
// fallback to nonconstexpr bit casts.
Expand Down
8 changes: 8 additions & 0 deletions include/universal/native/ieee754_numeric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ namespace sw { namespace universal {
return (std::fpclassify(a) == FP_ZERO);
}

// check if the floating-point number is a denorm
template<typename Real,
typename = typename ::std::enable_if< ::std::is_floating_point<Real>::value, Real >::type
>
inline bool isdenorm(const Real& a) {
return (std::fpclassify(a) == FP_SUBNORMAL);
}

// compile time power of 2
template<typename Real, size_t powerOfTwo,
typename = typename ::std::enable_if< ::std::is_floating_point<Real>::value, Real >::type
Expand Down
Loading

0 comments on commit 6a77dd9

Please sign in to comment.