├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── composer.json └── src ├── Calculator ├── BcmathCalculator.php ├── CalculatorFactory.php ├── CalculatorInterface.php ├── DefaultCalculator.php └── GmpCalculator.php ├── Exception └── ArithmeticException.php ├── Math.php └── Number ├── AbstractNumber.php ├── BigDecimal.php ├── BigInteger.php ├── Float.php ├── Integer.php └── NumberInterface.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # ramsey/math Changelog 2 | 3 | ## 1.0.0 4 | 5 | _Released: TBD_ 6 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project maintainer at . All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are welcome. We accept pull requests on [GitHub](https://github.com/ramsey/math). 4 | 5 | This project adheres to a [Contributor Code of Conduct](https://github.com/ramsey/math/blob/master/CODE_OF_CONDUCT.md). By participating in this project and its community, you are expected to uphold this code. 6 | 7 | ## Team members 8 | 9 | * [Ben Ramsey](https://github.com/ramsey) - original author and maintainer 10 | 11 | ## Communication Channels 12 | 13 | You can find help and discussion in the following places: 14 | 15 | * GitHub Issues: 16 | * Wiki: 17 | 18 | ## Reporting Bugs 19 | 20 | Bugs are tracked in our project's [issue tracker](https://github.com/ramsey/math/issues). 21 | 22 | When submitting a bug report, please include enough information for us to reproduce the bug. A good bug report includes the following sections: 23 | 24 | * Expected outcome 25 | * Actual outcome 26 | * Steps to reproduce, including sample code 27 | * Any other information that will help us debug and reproduce the issue, including stack traces, system/environment information, and screenshots 28 | 29 | **Please do not include passwords or any personally identifiable information in your bug report and sample code.** 30 | 31 | ## Fixing Bugs 32 | 33 | We welcome pull requests to fix bugs! 34 | 35 | If you see a bug report that you'd like to fix, please feel free to do so. Following the directions and guidelines described in the "Adding New Features" section below, you may create bugfix branches and send us pull requests. 36 | 37 | ## Adding New Features 38 | 39 | If you have an idea for a new feature, it's a good idea to check out our [issues](https://github.com/ramsey/math/issues) or active [pull requests](https://github.com/ramsey/math/pulls) first to see if the feature is already being worked on. If not, feel free to submit an issue first, asking whether the feature is beneficial to the project. This will save you from doing a lot of development work only to have your feature rejected. We don't enjoy rejecting your hard work, but some features just don't fit with the goals of the project. 40 | 41 | When you do begin working on your feature, here are some guidelines to consider: 42 | 43 | * Your pull request description should clearly detail the changes you have made. We will use this description to update our CHANGELOG. If there is no description or it does not adequately describe your feature, we will ask you to update the description. 44 | * We following the **[PSR-2 coding standard](http://www.php-fig.org/psr/psr-2/)**. Please ensure your code does, too. 45 | * Please **write tests** for any new features you add. 46 | * Please **ensure that tests pass** before submitting your pull request. We have Travis CI automatically running tests for pull requests. However, running the tests locally will help save time. 47 | * **Use topic/feature branches.** Please do not ask us to pull from your master branch. 48 | * **Submit one feature per pull request.** If you have multiple features you wish to submit, please break them up into separate pull requests. 49 | * **Send coherent history**. Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting. 50 | 51 | ## Running Tests 52 | 53 | The following tests must pass before we will accept a pull request. If any of these do not pass, it will result in a complete build failure. Before you can run these, be sure to `composer install`. 54 | 55 | ``` 56 | ./vendor/bin/parallel-lint src tests 57 | ./vendor/bin/phpcs src tests --standard=psr2 -sp 58 | ./vendor/bin/phpunit --coverage-text 59 | ``` 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Ben Ramsey 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ramsey/math 2 | 3 | [![Source Code][badge-source]][source] 4 | [![Latest Version][badge-release]][release] 5 | [![Software License][badge-license]][license] 6 | [![Build Status][badge-build]][build] 7 | [![HHVM Status][badge-hhvm]][hhvm] 8 | [![Scrutinizer][badge-quality]][quality] 9 | [![Coverage Status][badge-coverage]][coverage] 10 | [![Total Downloads][badge-downloads]][downloads] 11 | 12 | ramsey/math is a PHP 5.6+ mathematics library, including support for large numbers. 13 | 14 | This project adheres to a [Contributor Code of Conduct][conduct]. By participating in this project and its community, you are expected to uphold this code. 15 | 16 | 17 | ## About 18 | 19 | Much inspiration for this library came from the [Java][java] `Math` and `Number` classes. 20 | 21 | 22 | ## Installation 23 | 24 | TBD 25 | 26 | 27 | ## Examples 28 | 29 | TBD 30 | 31 | 32 | ## Contributing 33 | 34 | Contributions are welcome! Please read [CONTRIBUTING][] for details. 35 | 36 | 37 | ## Copyright and License 38 | 39 | The ramsey/math library is copyright © [Ben Ramsey](https://benramsey.com/) and licensed for use under the MIT License (MIT). Please see [LICENSE][] for more information. 40 | 41 | 42 | 43 | [conduct]: https://github.com/ramsey/math/blob/master/CODE_OF_CONDUCT.md 44 | [java]: http://docs.oracle.com/javase/8/docs/api/java/lang/Number.html 45 | [packagist]: https://packagist.org/packages/ramsey/math 46 | [composer]: http://getcomposer.org/ 47 | [apidocs]: http://docs.benramsey.com/ramsey-math/latest/ 48 | [contributing]: https://github.com/ramsey/math/blob/master/CONTRIBUTING.md 49 | 50 | [badge-source]: http://img.shields.io/badge/source-ramsey/math-blue.svg?style=flat-square 51 | [badge-release]: https://img.shields.io/github/release/ramsey/math.svg?style=flat-square 52 | [badge-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square 53 | [badge-build]: https://img.shields.io/travis/ramsey/math/master.svg?style=flat-square 54 | [badge-hhvm]: https://img.shields.io/hhvm/ramsey/math.svg?style=flat-square 55 | [badge-quality]: https://img.shields.io/scrutinizer/g/ramsey/math/master.svg?style=flat-square 56 | [badge-coverage]: https://img.shields.io/coveralls/ramsey/math/master.svg?style=flat-square 57 | [badge-downloads]: https://img.shields.io/packagist/dt/ramsey/math.svg?style=flat-square 58 | 59 | [source]: https://github.com/ramsey/math 60 | [release]: https://github.com/ramsey/math/releases 61 | [license]: https://github.com/ramsey/math/blob/master/LICENSE 62 | [build]: https://travis-ci.org/ramsey/math 63 | [hhvm]: http://hhvm.h4cc.de/package/ramsey/math 64 | [quality]: https://scrutinizer-ci.com/g/ramsey/math/ 65 | [coverage]: https://coveralls.io/r/ramsey/math?branch=master 66 | [downloads]: https://packagist.org/packages/ramsey/math 67 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ramsey/math", 3 | "abandoned": "brick/math", 4 | "description": "A PHP 5.6+ mathematics library, including support for large numbers.", 5 | "type": "library", 6 | "keywords": ["math", "number", "bcmath", "gmp", "arithmetic"], 7 | "homepage": "https://github.com/ramsey/math", 8 | "license": "MIT", 9 | "authors": [ 10 | { 11 | "name": "Ben Ramsey", 12 | "email": "ben@benramsey.com", 13 | "homepage": "https://benramsey.com" 14 | } 15 | ], 16 | "support": { 17 | "issues": "https://github.com/ramsey/math/issues", 18 | "source": "https://github.com/ramsey/math" 19 | }, 20 | "require": { 21 | "php": ">=5.6" 22 | }, 23 | "suggest": { 24 | "ext-bcmath": "If using the bcmath functionality", 25 | "ext-gmp": "If using the gmp functionality" 26 | }, 27 | "autoload": { 28 | "psr-4": { 29 | "Ramsey\\Math\\": "src/" 30 | } 31 | }, 32 | "autoload-dev": { 33 | "psr-4": { 34 | "Ramsey\\Math\\Test\\": "tests/src/" 35 | } 36 | }, 37 | "require-dev": { 38 | "phpunit/phpunit": "^4.7|^5.0", 39 | "squizlabs/php_codesniffer": "^2.3", 40 | "jakub-onderka/php-parallel-lint": "^0.9.0", 41 | "satooshi/php-coveralls": "^0.6.1" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Calculator/BcmathCalculator.php: -------------------------------------------------------------------------------- 1 | 9 | * @license http://opensource.org/licenses/MIT MIT 10 | * @link https://benramsey.com/projects/ramsey-math/ Documentation 11 | * @link https://packagist.org/packages/ramsey/math Packagist 12 | * @link https://github.com/ramsey/math GitHub 13 | */ 14 | 15 | namespace Ramsey\Math\Calculator; 16 | 17 | /** 18 | * A mathematical calculator using the PHP bcmath extension 19 | */ 20 | class BcmathCalculator implements CalculatorInterface 21 | { 22 | } 23 | -------------------------------------------------------------------------------- /src/Calculator/CalculatorFactory.php: -------------------------------------------------------------------------------- 1 | 9 | * @license http://opensource.org/licenses/MIT MIT 10 | * @link https://benramsey.com/projects/ramsey-math/ Documentation 11 | * @link https://packagist.org/packages/ramsey/math Packagist 12 | * @link https://github.com/ramsey/math GitHub 13 | */ 14 | 15 | namespace Ramsey\Math\Calculator; 16 | 17 | /** 18 | * A factory to retrieve an appropriate calculator for mathematical operations 19 | */ 20 | class CalculatorFactory 21 | { 22 | public function getCalculator() 23 | { 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Calculator/CalculatorInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * @license http://opensource.org/licenses/MIT MIT 10 | * @link https://benramsey.com/projects/ramsey-math/ Documentation 11 | * @link https://packagist.org/packages/ramsey/math Packagist 12 | * @link https://github.com/ramsey/math GitHub 13 | */ 14 | 15 | namespace Ramsey\Math\Calculator; 16 | 17 | /** 18 | * CalculatorInterface defines the common, core functionality of all calculator objects 19 | * that may be used by this library 20 | */ 21 | interface CalculatorInterface 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /src/Calculator/DefaultCalculator.php: -------------------------------------------------------------------------------- 1 | 9 | * @license http://opensource.org/licenses/MIT MIT 10 | * @link https://benramsey.com/projects/ramsey-math/ Documentation 11 | * @link https://packagist.org/packages/ramsey/math Packagist 12 | * @link https://github.com/ramsey/math GitHub 13 | */ 14 | 15 | namespace Ramsey\Math\Calculator; 16 | 17 | /** 18 | * A mathematical calculator using standard PHP mathematical operations 19 | */ 20 | class DefaultCalculator implements CalculatorInterface 21 | { 22 | } 23 | -------------------------------------------------------------------------------- /src/Calculator/GmpCalculator.php: -------------------------------------------------------------------------------- 1 | 9 | * @license http://opensource.org/licenses/MIT MIT 10 | * @link https://benramsey.com/projects/ramsey-math/ Documentation 11 | * @link https://packagist.org/packages/ramsey/math Packagist 12 | * @link https://github.com/ramsey/math GitHub 13 | */ 14 | 15 | namespace Ramsey\Math\Calculator; 16 | 17 | /** 18 | * A mathematical calculator using the PHP gmp extension 19 | */ 20 | class GmpCalculator implements CalculatorInterface 21 | { 22 | } 23 | -------------------------------------------------------------------------------- /src/Exception/ArithmeticException.php: -------------------------------------------------------------------------------- 1 | 9 | * @license http://opensource.org/licenses/MIT MIT 10 | * @link https://benramsey.com/projects/ramsey-math/ Documentation 11 | * @link https://packagist.org/packages/ramsey/math Packagist 12 | * @link https://github.com/ramsey/math GitHub 13 | */ 14 | 15 | namespace Ramsey\Math\Exception; 16 | 17 | /** 18 | * Thrown when an exceptional arithmetic condition has occurred 19 | * 20 | * For example, an integer "divide by zero" throws an instance of this class. 21 | */ 22 | class ArithmeticException extends \RuntimeException 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /src/Math.php: -------------------------------------------------------------------------------- 1 | 9 | * @license http://opensource.org/licenses/MIT MIT 10 | * @link https://benramsey.com/projects/ramsey-math/ Documentation 11 | * @link https://packagist.org/packages/ramsey/math Packagist 12 | * @link https://github.com/ramsey/math GitHub 13 | */ 14 | 15 | namespace Ramsey\Math; 16 | 17 | /** 18 | * The class Math contains methods for performing basic numeric operations such 19 | * as the elementary exponential, logarithm, square root, and trigonometric 20 | * functions 21 | */ 22 | class Math 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /src/Number/AbstractNumber.php: -------------------------------------------------------------------------------- 1 | 9 | * @license http://opensource.org/licenses/MIT MIT 10 | * @link https://benramsey.com/projects/ramsey-math/ Documentation 11 | * @link https://packagist.org/packages/ramsey/math Packagist 12 | * @link https://github.com/ramsey/math GitHub 13 | */ 14 | 15 | namespace Ramsey\Math\Number; 16 | 17 | /** 18 | * Represents a number 19 | */ 20 | abstract class AbstractNumber implements NumberInterface 21 | { 22 | } 23 | -------------------------------------------------------------------------------- /src/Number/BigDecimal.php: -------------------------------------------------------------------------------- 1 | 9 | * @license http://opensource.org/licenses/MIT MIT 10 | * @link https://benramsey.com/projects/ramsey-math/ Documentation 11 | * @link https://packagist.org/packages/ramsey/math Packagist 12 | * @link https://github.com/ramsey/math GitHub 13 | */ 14 | 15 | namespace Ramsey\Math\Number; 16 | 17 | /** 18 | * Immutable, arbitrary-precision signed decimal number 19 | */ 20 | class BigDecimal extends AbstractNumber 21 | { 22 | } 23 | -------------------------------------------------------------------------------- /src/Number/BigInteger.php: -------------------------------------------------------------------------------- 1 | 9 | * @license http://opensource.org/licenses/MIT MIT 10 | * @link https://benramsey.com/projects/ramsey-math/ Documentation 11 | * @link https://packagist.org/packages/ramsey/math Packagist 12 | * @link https://github.com/ramsey/math GitHub 13 | */ 14 | 15 | namespace Ramsey\Math\Number; 16 | 17 | /** 18 | * Immutable, arbitrary-precision integer 19 | */ 20 | class BigInteger extends AbstractNumber 21 | { 22 | } 23 | -------------------------------------------------------------------------------- /src/Number/Float.php: -------------------------------------------------------------------------------- 1 | 9 | * @license http://opensource.org/licenses/MIT MIT 10 | * @link https://benramsey.com/projects/ramsey-math/ Documentation 11 | * @link https://packagist.org/packages/ramsey/math Packagist 12 | * @link https://github.com/ramsey/math GitHub 13 | */ 14 | 15 | namespace Ramsey\Math\Number; 16 | 17 | /** 18 | * The Float class wraps a value of primitive type `float` in an object 19 | * 20 | * @link http://php.net/float 21 | */ 22 | class Float extends AbstractNumber 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /src/Number/Integer.php: -------------------------------------------------------------------------------- 1 | 9 | * @license http://opensource.org/licenses/MIT MIT 10 | * @link https://benramsey.com/projects/ramsey-math/ Documentation 11 | * @link https://packagist.org/packages/ramsey/math Packagist 12 | * @link https://github.com/ramsey/math GitHub 13 | */ 14 | 15 | namespace Ramsey\Math\Number; 16 | 17 | /** 18 | * The Integer class wraps a value of primitive type `integer` in an object 19 | * 20 | * @link http://php.net/integer 21 | */ 22 | class Integer extends AbstractNumber 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /src/Number/NumberInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * @license http://opensource.org/licenses/MIT MIT 10 | * @link https://benramsey.com/projects/ramsey-math/ Documentation 11 | * @link https://packagist.org/packages/ramsey/math Packagist 12 | * @link https://github.com/ramsey/math GitHub 13 | */ 14 | 15 | namespace Ramsey\Math\Number; 16 | 17 | /** 18 | * NumberInterface defines the common, core functionality of all number objects 19 | * that may be used by this library 20 | */ 21 | interface NumberInterface extends \JsonSerializable, \Serializable 22 | { 23 | public function compareTo($other); 24 | } 25 | --------------------------------------------------------------------------------