Skip to content

Solidity library with basic trigonometry functions

License

Notifications You must be signed in to change notification settings

fxfactorial/solidity-trigonometry

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Solidity library with basic trigonometry functions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Solidity 57.7%
  • Python 35.9%
  • Julia 3.8%
  • Shell 2.2%
  • Makefile 0.4%