Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Bać committed Jul 23, 2024
1 parent 50ce6e4 commit edc23c5
Show file tree
Hide file tree
Showing 21 changed files with 276 additions and 411 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ set( CMAKE_CXX_EXTENSIONS OFF)
add_subdirectory( fixed_lib )

if(PROJECT_IS_TOP_LEVEL AND FIXEDMATH_ENABLE_DEVEL_CODE)
add_subdirectory(perf_test_suite)
# add_subdirectory(perf_test_suite)
endif()

if( PROJECT_IS_TOP_LEVEL AND FIXEDMATH_ENABLE_UNIT_TESTS)
Expand Down
24 changes: 0 additions & 24 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
This library is available to anybody free of charge, under the terms of MIT License or Boost Software License - Version 1.0

Copyright (c) 2019-2021 arturbac (Artur Bać)

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
Expand Down
9 changes: 7 additions & 2 deletions examples/brief-usage.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// SPDX-FileCopyrightText: 2020-2024 Artur Bać
// SPDX-License-Identifier: BSL-1.0
// SPDX-PackageHomePage: https://github.com/arturbac/fixed_math

#include <fixedmath/fixed_math.hpp>
#include <fixedmath/iostream.h>

using fixedmath::fixed_t;
using fixedmath::operator""_fix;

// fixed and all functionality is constexpr so You can declare constants see features [1]
inline constexpr fixed_t foo_constant{fixedmath::tan(15 * fixedmath::phi / 180)};
inline constexpr fixed_t foo_constant{fixedmath::fobj::tan(15 * fixedmath::phi / 180)};

constexpr fixed_t my_function(fixed_t value)
{
using namespace fixedmath;
return foo_constant + sin(value) / (1.41_fix - 2 * cos(value) / 4);
// You can use funcioons or function objects
return foo_constant + fobj::sin(value) / (1.41_fix - 2 * func::cos(value) / 4);
}

int main()
Expand Down
26 changes: 3 additions & 23 deletions fixed_lib/include/fixedmath/core_ops.h
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
// MIT License
//
// Copyright (c) 2020-2021 Artur Bac
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// SPDX-FileCopyrightText: 2020-2024 Artur Bać
// SPDX-License-Identifier: BSL-1.0
// SPDX-PackageHomePage: https://github.com/arturbac/fixed_math

#pragma once
#include <cmath>
#include "types.h"
#include "limits.h"
#include "numbers.h"
#include "detail/common.h"
#include "detail/static_call_operator_prolog.h"

namespace fixedmath::inline v2
{
Expand Down Expand Up @@ -124,4 +105,3 @@ constexpr fixed_t::operator arithmethic_type() const noexcept

} // namespace fixedmath::inline v2

#include "detail/static_call_operator_epilog.h"
4 changes: 4 additions & 0 deletions fixed_lib/include/fixedmath/detail/common.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// SPDX-FileCopyrightText: 2020-2024 Artur Bać
// SPDX-License-Identifier: BSL-1.0
// SPDX-PackageHomePage: https://github.com/arturbac/fixed_math

#pragma once

#include "../types.h"
Expand Down

This file was deleted.

23 changes: 0 additions & 23 deletions fixed_lib/include/fixedmath/detail/static_call_operator_prolog.h

This file was deleted.

5 changes: 5 additions & 0 deletions fixed_lib/include/fixedmath/detail/type_traits.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// SPDX-FileCopyrightText: 2020-2024 Artur Bać
// SPDX-License-Identifier: BSL-1.0
// SPDX-PackageHomePage: https://github.com/arturbac/fixed_math

#pragma once

#include <cstdint>
#include <concepts>
#include <type_traits>
Expand Down
25 changes: 4 additions & 21 deletions fixed_lib/include/fixedmath/detail/utility_cxx20.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
// MIT License
//
// Copyright (c) 2020-2021 Artur Bac
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// SPDX-FileCopyrightText: 2020-2024 Artur Bać
// SPDX-License-Identifier: BSL-1.0
// SPDX-PackageHomePage: https://github.com/arturbac/fixed_math

#pragma once

#if !defined(SMALL_VECTORS_CXX_UTILITY)
Expand Down
24 changes: 3 additions & 21 deletions fixed_lib/include/fixedmath/fixed_math.hpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
// MIT License
//
// Copyright (c) 2020-2021 Artur Bac
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// SPDX-FileCopyrightText: 2020-2024 Artur Bać
// SPDX-License-Identifier: BSL-1.0
// SPDX-PackageHomePage: https://github.com/arturbac/fixed_math

#pragma once

Expand Down
45 changes: 14 additions & 31 deletions fixed_lib/include/fixedmath/iostream.h
Original file line number Diff line number Diff line change
@@ -1,38 +1,21 @@
// MIT License
//
// Copyright (c) 2020-2021 Artur Bac
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// SPDX-FileCopyrightText: 2020-2024 Artur Bać
// SPDX-License-Identifier: BSL-1.0
// SPDX-PackageHomePage: https://github.com/arturbac/fixed_math

#pragma once
#include "math.h"

#include <iostream>
#include <iomanip>

namespace fixedmath
{
inline std::ostream & operator << ( std::ostream & outstr, fixed_t src )
{
if( src != std::numeric_limits<fixed_t>::quiet_NaN() )
outstr << std::fixed << std::setprecision( 16 ) << static_cast<double>( src );
else
outstr << "NaN";
return outstr;
}
}
{
inline std::ostream & operator<<(std::ostream & outstr, fixed_t src)
{
if(src != std::numeric_limits<fixed_t>::quiet_NaN())
outstr << std::fixed << std::setprecision(16) << static_cast<double>(src);
else
outstr << "NaN";
return outstr;
}
} // namespace fixedmath
123 changes: 57 additions & 66 deletions fixed_lib/include/fixedmath/limits.h
Original file line number Diff line number Diff line change
@@ -1,75 +1,66 @@
// MIT License
//
// Copyright (c) 2020-2021 Artur Bac
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// SPDX-FileCopyrightText: 2020-2024 Artur Bać
// SPDX-License-Identifier: BSL-1.0
// SPDX-PackageHomePage: https://github.com/arturbac/fixed_math

#pragma once

#include "types.h"

namespace fixedmath
{

}
{
}

namespace std
{
template<>
struct numeric_limits<fixedmath::fixed_t>
{
using value_type = fixedmath::fixed_t;
using fixed_internal = fixedmath::fixed_internal;
using fix_carrier_t = fixedmath::fix_carrier_t;

static constexpr bool is_integer { false };
static constexpr bool is_specialized { true };
static constexpr bool is_signed { true };
static constexpr bool is_exact{ true };
static constexpr bool has_infinity{};
static constexpr bool has_quiet_NaN{ true };
static constexpr bool has_signaling_NaN{};
static constexpr bool has_denorm_loss{};
static constexpr float_round_style round_style{round_toward_zero};
static constexpr bool is_iec559{};
static constexpr bool is_bounded{true};
static constexpr bool is_modulo{};
static constexpr int digits{16};
static constexpr int digits10{4};
static constexpr int max_digits10{6};
static constexpr int radix{2};
static constexpr bool traps{true};
static constexpr bool tinyness_before{};

static consteval value_type min() noexcept{ return fix_carrier_t{fixed_internal{1}}; }
static consteval value_type lowest() noexcept{ return fix_carrier_t{fixed_internal{-0x7FFFFFFFFFFFFFFEll}}; }
static consteval value_type max() noexcept { return fix_carrier_t{fixed_internal{0x7FFFFFFFFFFFFFFEll}}; }
static consteval value_type one() noexcept { return fix_carrier_t{fixed_internal{65536}}; }
static consteval value_type epsilon() noexcept { return fix_carrier_t{fixed_internal{1}}; }
static consteval value_type round_error() noexcept { return fix_carrier_t{fixed_internal{1}}; }
static consteval value_type quiet_NaN() noexcept { return fix_carrier_t{fixed_internal{0x7FFFFFFFFFFFFFFFll}}; }

static consteval int32_t max_integral() noexcept { return 2147483647; }
static consteval int32_t min_integral() noexcept{ return -2147483647; }
};

}
{
template<>
struct numeric_limits<fixedmath::fixed_t>
{
using value_type = fixedmath::fixed_t;
using fixed_internal = fixedmath::fixed_internal;
using fix_carrier_t = fixedmath::fix_carrier_t;

static constexpr bool is_integer{false};
static constexpr bool is_specialized{true};
static constexpr bool is_signed{true};
static constexpr bool is_exact{true};
static constexpr bool has_infinity{};
static constexpr bool has_quiet_NaN{true};
static constexpr bool has_signaling_NaN{};
static constexpr bool has_denorm_loss{};
static constexpr float_round_style round_style{round_toward_zero};
static constexpr bool is_iec559{};
static constexpr bool is_bounded{true};
static constexpr bool is_modulo{};
static constexpr int digits{16};
static constexpr int digits10{4};
static constexpr int max_digits10{6};
static constexpr int radix{2};
static constexpr bool traps{true};
static constexpr bool tinyness_before{};

static consteval value_type min() noexcept { return fix_carrier_t{fixed_internal{1}}; }

static consteval value_type lowest() noexcept { return fix_carrier_t{fixed_internal{-0x7FFFFFFFFFFFFFFEll}}; }

static consteval value_type max() noexcept { return fix_carrier_t{fixed_internal{0x7FFFFFFFFFFFFFFEll}}; }

static consteval value_type one() noexcept { return fix_carrier_t{fixed_internal{65536}}; }

static consteval value_type epsilon() noexcept { return fix_carrier_t{fixed_internal{1}}; }

static consteval value_type round_error() noexcept { return fix_carrier_t{fixed_internal{1}}; }

static consteval value_type quiet_NaN() noexcept { return fix_carrier_t{fixed_internal{0x7FFFFFFFFFFFFFFFll}}; }

static consteval int32_t max_integral() noexcept { return 2147483647; }

static consteval int32_t min_integral() noexcept { return -2147483647; }
};

} // namespace std

namespace fixedmath
{
{
inline consteval auto quiet_NaN_result() -> fixed_t { return std::numeric_limits<fixed_t>::quiet_NaN(); }
}
} // namespace fixedmath

Loading

0 comments on commit edc23c5

Please sign in to comment.