{"id":20254783,"url":"https://github.com/chippyash/math-type-calculator","last_synced_at":"2025-04-11T00:03:53.006Z","repository":{"id":19003860,"uuid":"22226272","full_name":"chippyash/Math-Type-Calculator","owner":"chippyash","description":"Basic arithmetic operations for the chippyash/Strong-Type library of strong PHP numeric types","archived":false,"fork":false,"pushed_at":"2018-07-05T16:55:11.000Z","size":185,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T00:03:46.120Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chippyash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-24T18:58:01.000Z","updated_at":"2018-07-05T16:55:12.000Z","dependencies_parsed_at":"2022-09-25T03:31:27.742Z","dependency_job_id":null,"html_url":"https://github.com/chippyash/Math-Type-Calculator","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chippyash%2FMath-Type-Calculator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chippyash%2FMath-Type-Calculator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chippyash%2FMath-Type-Calculator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chippyash%2FMath-Type-Calculator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chippyash","download_url":"https://codeload.github.com/chippyash/Math-Type-Calculator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248317705,"owners_count":21083528,"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-11-14T10:34:53.817Z","updated_at":"2025-04-11T00:03:52.981Z","avatar_url":"https://github.com/chippyash.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chippyash/math-type-calculator\n\n## Quality Assurance\n\n![PHP 5.4](https://img.shields.io/badge/PHP-5.4-blue.svg)\n![PHP 5.5](https://img.shields.io/badge/PHP-5.5-blue.svg)\n![PHP 5.6](https://img.shields.io/badge/PHP-5.6-blue.svg)\n![PHP 7](https://img.shields.io/badge/PHP-7-blue.svg)\n[![Build Status](https://travis-ci.org/chippyash/Math-Type-Calculator.svg?branch=master)](https://travis-ci.org/chippyash/Math-Type-Calculator)\n[![Test Coverage](https://codeclimate.com/github/chippyash/Math-Type-Calculator/badges/coverage.svg)](https://codeclimate.com/github/chippyash/Math-Type-Calculator/coverage)\n[![Code Climate](https://codeclimate.com/github/chippyash/Math-Type-Calculator/badges/gpa.svg)](https://codeclimate.com/github/chippyash/Math-Type-Calculator)\n\nSee the [test contract](https://github.com/chippyash/Math-Type-Calculator/blob/master/docs/Test-Contract.md).\n\nThe above badges represent the current master branch.  As a rule, I don't push\n to GitHub unless tests, coverage and usability are acceptable.  This may not be\n true for short periods of time; on holiday, need code for some other downstream\n project etc.  If you need stable code, use a tagged version. Read 'Further Documentation'\n and 'Installation'.\n \nCurrent development branch is feature/gmp_support. Want to help? - that's where it is.\n\nPlease note that developer support for PHP5.4 \u0026 5.5 was withdrawn at version 3.0.0 of this library.\nIf you need support for PHP 5.4 or 5.5, please use a version `\u003e=2,\u003c3`\n \n## What?\n\nProvides arithmetic calculation support for chippyash/strong-type numeric types, (PHP\nnative types only at this point.)\n\n### Types supported\n\n*  FloatType\n*  ComplexType\n*  IntType\n*  NaturalIntType\n*  WholeIntType\n*  RationalType\n*  Conversion of PHP int and float to IntType and FloatType respectively\n\n### Arithmetic support provided\n\n*  addition\n*  subtraction\n*  multiplication\n*  division\n*  reciprocal\n*  equality comparison\n\nThe library is released under the [GNU GPL V3 or later license](http://www.gnu.org/copyleft/gpl.html)\n\n## Why?\n\nComplements the strong-type library and a precursor to the forthcoming chippyash/math-matrix\nlibrary which builds on the chippyash/matrix library.\n\n## When\n\nThe current library covers arithmetic operations using PHP native math support.\nFuture versions will add support for the popular math extensions (gmp, bcmath etc).\n\nIf you want more, either suggest it, or better still, fork it and provide a pull request.\n\nCheck out [chippyash/Strong-Type](https://github.com/chippyashl/Strong-Type) for strong type including numeric,\nrational and complex type support, that this library operates on\n\nCheck out [chippyash/Matrix](https://github.com/chippyash/Matrix) for Matrix data type support.\n\nCheck out [chippyash/Logical-Matrix](https://github.com/chippyash/Logical-matrix) for logical matrix operations\n\nCheck out [chippyash/Math-Matrix](https://github.com/chippyash/Math-Matrix) for mathematical matrix operations\n\nCheck out [ZF4 Packages](http://zf4.biz/packages?utm_source=github\u0026utm_medium=web\u0026utm_campaign=blinks\u0026utm_content=typecalculator) for more packages\n\n## How\n\n### Coding Basics\n\nUsing the supplied calculator or comparator will set the underlying Strong Type\nnumeric base to PHP Native.  This library does not yet support GMP number types.\n\n#### Calculations\n\nUsing the calculator is simplicity itself:\n\n\u003cpre\u003e\n    use Chippyash\\Math\\Type\\Calculator;\n\n    $calc = new Calculator()\n\u003c/pre\u003e\n\nThen you simply fire calculation requests at it:\n\n\u003cpre\u003e\n    use Chippyash\\Type\\TypeFactory;\n\n    $r = TypeFactory::create('rational', 2, 3);\n    $i = TypeFactory::create('int', 23);\n    $w = TypeFactory::create('whole', 3);\n    $n = TypeFactory::create('natural', 56);\n    $f = TypeFactory::create('float', 19.6);\n    $c1 = TypeFactory::create('complex', '2+3i');\n    $c2 = TypeFactory::create('complex', '-6+4i');\n\n    echo $calc-\u003eadd($r, $w) . PHP_EOL;\n    echo $calc-\u003eadd($c1, $c2) . PHP_EOL;\n    echo $calc-\u003eadd($i, $f) . PHP_EOL;\n    echo $calc-\u003esub($c1, $c2) . PHP_EOL;\n    echo $calc-\u003esub($n, $w) . PHP_EOL;\n    echo $calc-\u003eadd($r, $w) . PHP_EOL;\n    echo $calc-\u003eadd($r, $w) . PHP_EOL;\n    echo $calc-\u003eadd($r, $w) . PHP_EOL;\n\u003c/pre\u003e\n\nThe Calculator supports the following methods (all operands are NumericTypeInterface, or PHP int or PHP float):\n\n*  add($a, $b) : NumericTypeInterface\n*  sub($a, $b) : NumericTypeInterface\n*  mul($a, $b  : NumericTypeInterface\n*  div($a, $b) : NumericTypeInterface\n*  reciprocal($a) : NumericTypeInterface\n*  pow($base, $exp) : NumericTypeInterface\n*  sqrt($a) : NumericTypeInterface\n\nThe Calculator will arbitrate between types and return the lowest possible type based on the operand types.\nThe order of precedence is\n\n*  ComplexType\n*  RationalType\n*  FloatType\n*  IntType (including WholeIntType and NaturalIntType)\n\nBe careful with complex types, they can only be converted down if they are real, i.e. the imaginary part == 0\n\nThe sqrt() method is provided as a convenience, you can use pow(n, 1/e) e.g. pow(4, 1/2) == sqrt(4)\n\nFor a demonstration of all the available operations between types and their\nresultant types run the examples/example-calc.php file\n\n#### Comparisons\n\nTo compare two numeric types:\n\n\u003cpre\u003e\n    use Chippyash\\Math\\Type\\Comparator;\n    use Chippyash\\Type\\TypeFactory;\n\n    $r = TypeFactory::create('rational', 2, 3);\n    $i = TypeFactory::create('int', 23);\n    $w = TypeFactory::create('whole', 3);\n    $n = TypeFactory::create('natural', 56);\n    $f = TypeFactory::create('float', 19.6);\n    $c1 = TypeFactory::create('complex', '2+3i');\n    $c2 = TypeFactory::create('complex', '-6+4i');\n\n    $comp = new Comparator();\n\n    if ($comp-\u003ecompare($r, $i) == 0) {...}\n    if ($comp-\u003ecompare($c1, $c2) == -1) {...}\n    if ($comp-\u003ecompare($w, $n) == 1) {...}\n\u003c/pre\u003e\n\nThe Comparator::compare($a, $b) method takes two NumericTypeInterface types and returns\n\n    a == b: 0\n    a \u003c b : -1\n    a \u003e b : 1\n\nIt has convenience methods (all operands are NumericTypeInterface):\n\n*  eq($a, $b) : boolean: $a == $b\n*  neq($a, $b) : boolean: $a != $b\n*  lt($a, $b) : boolean: $a \u003c $b\n*  lte($a, $b) : boolean: $a \u003c= $b\n*  gt($a, $b) : boolean: $a \u003e $b\n*  gte($a, $b) : boolean: $a \u003e= $b\n\n\u003cpre\u003e\n    if ($comp-\u003egt($w, $f) { ... }\n\u003c/pre\u003e\n\n### Changing the library\n\n1.  fork it\n2.  write the test\n3.  amend it\n4.  do a pull request\n\nFound a bug you can't figure out?\n\n1.  fork it\n2.  write the test\n3.  do a pull request\n\nNB. Make sure you rebase to HEAD before your pull request\n\n## Where?\n\nThe library is hosted at [Github](https://github.com/chippyash/Math-Type-Calculator). It is\navailable at [Packagist.org](https://packagist.org/packages/chippyash/math-type-calculator)\n\n### Installation\n\nInstall [Composer](https://getcomposer.org/)\n\n#### For production\n\nadd\n\n\u003cpre\u003e\n    \"chippyash/math-type-calculator\": \"\u003e=3,\u003c4\"\n\u003c/pre\u003e\n\nto your composer.json \"requires\" section\n\n#### For development\n\nClone this repo, and then run Composer in local repo root to pull in dependencies\n\n\u003cpre\u003e\n    git clone git@github.com:chippyash/chippyash/Math-Type-Calculator.git TypeCalc\n    cd TypeCalc\n    composer update\n\u003c/pre\u003e\n\nTo run the tests:\n\n\u003cpre\u003e\n    cd TypeCalc\n    vendor/bin/phpunit -c test/phpunit.xml test/\n\u003c/pre\u003e\n\n## License\n\nThis software library is released under the [BSD 3 Clause license](https://opensource.org/licenses/BSD-3-Clause)\n\nThis software library is Copyright (c) 2015-2018, Ashley Kitson, UK\n\n## History\n\nV0...  pre releases\n\nV1.0.0 Original release\n\nV1.0.1 Add ability to mix complex and non complex types as operands\n\nV1.0.2 Utilise chippyash/strong-type \u003e= 1.0.10\n\nV1.1.0 Add comparator class for equality comparison\n\nV1.1.1 Fix bad comparator construction\n\nV1.1.2 Fix native int/float comparison by casting to rational\n\nV1.1.4 Refactor for dependent library\n\nV1.1.5 Update dependent version number\n\nV1.1.6 Add pow and square root functionality\n\nV1.1.7 Add complex pow using complex exponent\n\nV1.1.8 Update dependent version number\n\nV1.1.9 Update dependent version number\nV1.1.9a Bump to fix failing build\n\nV1.1.10 Fix calculator to use Native PHP numeric types until GMP calculator support is available\n\nV2.0.0 BC Break: change namespace from chippyash\\Math to Chippyash\\Math\\Type\n  \nV2.0.1 Add link to packages\n\nV2.0.2 Ensure compatibility with PHP7\n\nV2.0.3 Dependency update\n\nV3.0.0 BC Break. Withdraw support for old PHP versions\n\nV3.1.0 Change of license from GPL V3 to BSD 3 Clause \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchippyash%2Fmath-type-calculator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchippyash%2Fmath-type-calculator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchippyash%2Fmath-type-calculator/lists"}