Git Product home page Git Product logo

solidity-trigonometry's Introduction

Solidity Trigonometry

Solidity library offering basic trigonometry functions where inputs and outputs are integers. Inputs are specified in radians scaled by 1e18, and similarly outputs are scaled by 1e18. Each invocation of the sin() and cos() functions cost around 2000โ€“2500 gas (see .gas-snapshot) for more info.

This implementation is based off the Solidity trigonometry library written by Lefteris Karapetsas which can be found here. Compared to Lefteris' implementation, this version makes the following changes:

  • Uses a 32 bits instead of 16 bits for improved accuracy
  • Updated for Solidity 0.8.x
  • Various gas optimizations
  • Change inputs/outputs to standard trig format (scaled by 1e18) instead of requiring the integer format used by the algorithm

The original implementation by Lefteris is based off Dave Dribin's trigint C library, which in turn is based on an article by Scott Dattalo.

Usage

To use this in a dapptools project, install it with:

dapp install https://github.com/mds1/solidity-trigonometry

There is currently no npm package, so for projects using Hardhat or other development frameworks, use:

yarn add https://github.com/mds1/solidity-trigonometry.git

Development

This library is developed with dapptools.

To update gas snapshots:

  1. Install duppgrade
  2. Switch dapptools to the WIP branch with gas snapshot functionality with duppgrade gas-snapshot-dev
  3. Run dapp --snapshot

solidity-trigonometry's People

Contributors

mds1 avatar gfxlabs avatar transmissions11 avatar

Watchers

James Cloos avatar

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.