#define SG14_FIXED_POINT_H 1
#include "type_traits.h"
#include "bits/common.h"
#define SG14_FIXED_POINT_EXCEPTIONS_ENABLED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Signed 15:16 Fixed-Point Square Function Using sg14::elastic | |
| // Here's how to use the fixed_point library on Godbolt.org. | |
| // Normally, you'd just add `#include <sg14/fixed_point>`. | |
| #define SG14_GODBOLT_ORG | |
| #include <https://raw.githubusercontent.com/johnmcfarlane/fixed_point/develop/include/sg14/bits/config.h> | |
| #include <https://raw.githubusercontent.com/johnmcfarlane/fixed_point/develop/include/sg14/bits/config.h> | |
| #include <https://raw.githubusercontent.com/johnmcfarlane/fixed_point/develop/include/sg14/cstdint> | |
| #include <https://raw.githubusercontent.com/johnmcfarlane/fixed_point/develop/include/sg14/limits> | |
| #include <https://raw.githubusercontent.com/johnmcfarlane/fixed_point/develop/include/sg14/type_traits> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <algorithm> | |
| #include <limits> | |
| template<typename Number = int, typename Counter = int> | |
| class stats { | |
| public: | |
| void sample(Number const & n) { | |
| _sum += n; | |
| _count ++; | |
| _minimum = std::min(_minimum, n); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <array> | |
| #include <atomic> | |
| #include <complex> | |
| #include <cstddef> | |
| #include <functional> | |
| #include <list> | |
| #include <memory> | |
| #include <string> | |
| #include <type_traits> | |
| #include <unordered_map> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Signed 15:16 Fixed-Point Square Function Using sg14::elastic | |
| #include <https://gist.githubusercontent.com/johnmcfarlane/23b8bc5fefb77d482306c5bc837b5df1/raw/ed6cdfc3de42ae3c140bbbdd0ce5b8bc131d1f02/fixed_point.h> | |
| using namespace sg14; | |
| // square a nunber using 15:16 fixed-point arithmetic | |
| // without using a fixed-point library | |
| float square_int(float input) { | |
| // user must scale values by the correct amount |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Copyright John McFarlane 2015 - 2016. | |
| // Distributed under the Boost Software License, Version 1.0. | |
| // (See accompanying file ../LICENSE_1_0.txt or copy at | |
| // http://www.boost.org/LICENSE_1_0.txt) | |
| /// \file | |
| /// \brief essential definitions related to the `sg14::elastic` type | |
| #define SG14_USE_INT128 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace iso_4217 { | |
| struct code { | |
| const char* entity; | |
| const char* currency; | |
| const char* alpha; | |
| int numeric; | |
| int minor_unit; | |
| }; | |
| constexpr const char* currency_na = nullptr; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static auto start = std::chrono::system_clock::now(); | |
| auto t = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::system_clock::now() - start).count(); |
Header file fixed_point.h
#define SG14_FIXED_POINT_H 1
#include "type_traits.h"
#include "bits/common.h"
#define SG14_FIXED_POINT_EXCEPTIONS_ENABLED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // functor.c : Illustrates run-time polymorphism in C. | |
| // | |
| #include <memory.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| //////////////////////////////////////////////////////////////////////////////// | |
| // APIs |