{"id":13620648,"url":"https://github.com/mds1/solidity-trigonometry","last_synced_at":"2025-03-17T02:31:29.930Z","repository":{"id":46211251,"uuid":"423275197","full_name":"mds1/solidity-trigonometry","owner":"mds1","description":"Solidity library with basic trigonometry functions","archived":false,"fork":false,"pushed_at":"2023-03-09T04:22:15.000Z","size":85,"stargazers_count":148,"open_issues_count":0,"forks_count":18,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-27T16:47:27.253Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mds1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-10-31T22:33:53.000Z","updated_at":"2025-01-13T21:37:40.000Z","dependencies_parsed_at":"2024-01-21T18:57:14.286Z","dependency_job_id":null,"html_url":"https://github.com/mds1/solidity-trigonometry","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mds1%2Fsolidity-trigonometry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mds1%2Fsolidity-trigonometry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mds1%2Fsolidity-trigonometry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mds1%2Fsolidity-trigonometry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mds1","download_url":"https://codeload.github.com/mds1/solidity-trigonometry/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243841125,"owners_count":20356440,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T21:00:58.048Z","updated_at":"2025-03-17T02:31:29.624Z","avatar_url":"https://github.com/mds1.png","language":"Solidity","funding_links":[],"categories":["Libraries","Projects Using Dapp"],"sub_categories":[],"readme":"# Solidity Trigonometry\n\nSolidity library offering basic trigonometry functions where inputs and outputs are integers.\nInputs are specified in radians scaled by 1e18, and similarly outputs are scaled by 1e18.\nEach invocation of the `sin()` and `cos()` functions cost around 1600\u0026ndash;1700 gas (see the `testNoReverts` costs in `.gas-snapshot` for more info).\n\nThis implementation is based off the Solidity trigonometry library written by\n[Lefteris Karapetsas](https://twitter.com/LefterisJP)\nwhich can be found [here](https://github.com/Sikorkaio/sikorka/blob/e75c91925c914beaedf4841c0336a806f2b5f66d/contracts/trigonometry.sol).\nCompared to Lefteris' implementation, this version makes the following changes:\n- Uses a 32 bits instead of 16 bits for improved accuracy\n- Updated for Solidity 0.8.x\n- Various gas optimizations\n- Change inputs/outputs to standard trig format (scaled by 1e18) instead of requiring the integer format used by the algorithm\n\nThe original implementation by Lefteris is based off Dave Dribin's [trigint](http://www.dribin.org/dave/trigint/) C library,\nwhich in turn is based on an [article](http://web.archive.org/web/20120301144605/http://www.dattalo.com/technical/software/pic/picsine.html) by Scott Dattalo.\n\n## Usage\n\nWhen using this library, it's recommended to wrap input values (which are in radians) between `2 * PI * 1e18` and `4 * PI * 1e18` to avoid precision errors.\nThis is equivalent to wrapping standard values between 0 and 2π. There is some flexibility on that range, but it should stay within reasonable bounds.\n\nTo use this in a [Foundry](https://github.com/gakonst/foundry/) project, install it with:\n\n```sh\nforge install https://github.com/mds1/solidity-trigonometry\n```\n\nTo use this in a [dapptools](https://github.com/dapphub/dapptools/) project, install it with:\n\n```sh\ndapp install https://github.com/mds1/solidity-trigonometry\n```\n\nThere is currently no npm package, so for projects using npm for package management, such as [Hardhat](https://hardhat.org/) projects, use:\n\n```sh\nyarn add https://github.com/mds1/solidity-trigonometry.git\n```\n\n## Development\n\n### Setup\n\nThis library is developed with [Foundry](https://github.com/dapphub/dapptools/).\nIf you don't have Foundry installed, run the command below to get `foundryup`, the Foundry toolchain installer:\n\n```\ncurl -L https://foundry.paradigm.xyz | bash\n```\n\nThen in a new terminal session or after reloading your PATH, run `foundryup` to get the latest `forge` and `cast` binaries.\n\n\n### Testing\n\nRun tests with `forge test`, and update gas snapshots with `FOUNDRY_FUZZ_RUNS=50000 forge snapshot` (this will take a while to run since that many FFI runs can be slow).\n\nNOTE: Tests are configured to run with the `--ffi` flag enabled for fuzz testing, so review the test commands before executing them to ensure you aren't running any malicious code on your machine.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmds1%2Fsolidity-trigonometry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmds1%2Fsolidity-trigonometry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmds1%2Fsolidity-trigonometry/lists"}