This file contains 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 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 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 2017. | |
// 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) | |
// mechanically retrieved, single-header version of fixed_point library | |
// https://github.com/johnmcfarlane/fixed_point | |
#if ! defined(SG14_FIXED_POINT_SINGLE_HEADER) |
This file contains 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
// here is a very small header |
This file contains 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
<code_scheme name="jmcf"> | |
<Objective-C> | |
<option name="INDENT_NAMESPACE_MEMBERS" value="0" /> | |
<option name="INDENT_C_STRUCT_MEMBERS" value="2" /> | |
<option name="INDENT_CLASS_MEMBERS" value="2" /> | |
<option name="INDENT_INSIDE_CODE_BLOCK" value="2" /> | |
<option name="KEEP_STRUCTURES_IN_ONE_LINE" value="true" /> | |
<option name="KEEP_CASE_EXPRESSIONS_IN_ONE_LINE" value="true" /> | |
<option name="FUNCTION_NON_TOP_AFTER_RETURN_TYPE_WRAP" value="0" /> | |
<option name="FUNCTION_TOP_AFTER_RETURN_TYPE_WRAP" value="0" /> |
This file contains 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 <stdlib.h> | |
namespace a_namespace{ | |
constexpr int x = 6; | |
#if defined TEST | |
#error The test passed (ironically) | |
#endif | |
} |
This file contains 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 <functional> | |
#include <memory> | |
#include <stdlib.h> | |
#if defined(USE_ALTERNATIVE) | |
template<class FunctionSignature> | |
class function; | |
template<class Result, class...Args> |
This file contains 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
// examples from Krister Walfridsson's "How undefined signed overflow enables optimizations in GCC": | |
// https://kristerw.blogspot.com/2016/02/how-undefined-signed-overflow-enables.html | |
// https://godbolt.org/g/Hw797e | |
// Other relevant material: | |
// [CppCon 2016: Jon Kalb “unsigned: A Guideline for Better Code"](https://www.youtube.com/watch?v=wvtFGa6XJDU) | |
// [CppCon 2016: Chandler Carruth “Garbage In, Garbage Out: Arguing about Undefined Behavior..."](https://www.youtube.com/watch?v=yG1OZ69H_-o&t=2542s) | |
#include <algorithm> |
This file contains 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 <cnl/fixed_point.h> | |
#include <array> | |
using namespace cnl; | |
using namespace std; | |
constexpr int mandelbrot(float f_x, float f_y, int const limit) { | |
using scalar = fixed_point<int64_t, -28>; | |
auto c_x = scalar{f_x}; | |
auto c_y = scalar{f_y}; |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Title</title> | |
<meta charset="utf-8"> | |
<style> | |
@import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz); | |
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic); | |
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic); |