Giter VIP home page Giter VIP logo

pt_math's Introduction

pt_math.h

This is a set of branch-free, table-free implementations of the math functions in <math.h>.

All of the code is "public domain"1 - if you like, you can copy out the sin implementation if that's all you need.

These functions differ slightly from the C standard library by design - to stay fast, they don't do range checking by default, or follow C's precision requirements. Think of these routines more as "decent approximations", for when you know the particular input domain and you have leeway with the output. Video games are a good use case.

C compatibility

These functions stick to the C API, but the library doesn't implement all of math.h - notable exclusions are machine-related functions (e.g. fma, nextafter), precision-related functions (e.g. expm1), complex numbers, and tgamma/lgamma. The standard elementary functions that you would expect are included, as well as hyperbolic trig.

Functionality

The library uses a select few functions, fully implemented from scratch, in order to derive the implementation of others via identities. For example, cos(x) is implemented as sin(x + ฯ€/2), and tan(x) is implemented as sin(x)/cos(x). This simplifies many of the routines, since the potential precision loss from this approach is negligible within the given bounds of the library.

Exceptions to branch-free rule

  • atan2 is highly discontinuous, so a truly branch-free implementation of this routine is likely impossible.

License & Credits

I want this library to be easy to use, so no attribution is necessary.

1Actual public domain dedications are of unclear legality worldwide, so an equivalent permissive license (no-clause BSD) is used, available at the bottom of the file.

Algorithm credit:

pt_math's People

Contributors

pmttavara avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pt_math's Issues

Would you be willing to consider releasing this under CC0?

Some people will view "zero-clause BSD" as not truly public domain, but CC0 as being so. Yet CC0 does attempt to address the "public domain dedication might not be legally possible in certain countries" issue.

Another option, is "disjunctive licensing". You could change the license notice at the bottom of the file to say something like this:

/* You may use this software under EITHER of the below licenses, at your option:

OPTION 1

Under the terms of CC0 1.0 Universal, available at: https://creativecommons.org/publicdomain/zero/1.0/legalcode.txt 

OPTION 2

Copyright (c) Phillip Trudeau-Tavara, 2017-2019. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.