PHPackages                             xxc/fractionmath - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. xxc/fractionmath

ActiveProject[Utility &amp; Helpers](/categories/utility)

xxc/fractionmath
================

Package for doing math operations with Fractions

1.6(7y ago)040MITPHP

Since Nov 22Pushed 7y ago1 watchersCompare

[ Source](https://github.com/xxaxxo/FractionMath)[ Packagist](https://packagist.org/packages/xxc/fractionmath)[ RSS](/packages/xxc-fractionmath/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (8)Used By (0)

Composer package for math operations with fractions
===================================================

[](#composer-package-for-math-operations-with-fractions)

[![Latest Version](https://camo.githubusercontent.com/294692a28f24ab63466970bdb2207d31e734bdcb6476fb6dd4bb390e58404d4d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f78786178786f2f4672616374696f6e4d6174682e7376673f7374796c653d666c61742d737175617265)](https://github.com/xxaxxo/FractionMath/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/48b11873780a18da22a634f2f520661711091b8124aad58749a05ee53d05ad4e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f78786178786f2f4672616374696f6e4d6174682f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/xxaxxo/FractionMath)

Auto simplifies the fractions on initialisation. Installation:

```
 composer require xxc/fractionmath:1.*
```

Usage:

```
$fraction = new Fraction(1,2);
$fraction->display();
```

Available methods for a Fraction:

- numerator() - gets the numerator
- denominator() - gets the denominator
- integer() - gets the integer
- getGreatestCommonDivisor() - gets the GCD of the numetor and the denominator
- getFractionAsArray() - returns the fraction as array with keys numerator, denominator, integer
- getFractionAsObject() - returns the fraction as object
- display() - returns the html for a fraction
- parse() - static method for quick parsing strings to fractions

Works with irregular fractions aswell ```
$fraction = new Fraction(9,3);
$fraction->getFractionAsArray();
/*
returns ...
  array(
    'numerator' => 9,
    'denominator' => 3,
    'integer' => 0
    );
    */
```

If you need you can parse strings to fractions with the static parse method. The method accepts a string param in the format integer-space-nominator-slash-deniminator - Example for valid inputs: 1/2; 5 1/2; 5/6; 666 1/5;

```
xxc\fractionmath\Fraction::parse('1/2'); \\returns a fraction with nominator 1 and denominator 2
xxc\fractionmath\Fraction::parse('3 1/2'); \\returns a fraction with integer 3,nominator 1 and denominator 2
\\you can chain methods like this
xxc\fractionmath\Fraction::parse('2/4')->display(); \\returns html for a fraction 2/4
```

The Math class handles all the math operations - requires Fraction as inputs and returns a Fraction
Math operations:

- add()
- subtract()
- multiply()
- divide()

```
$fractionOne = new Fraction(1,3);
$fractionTwo = new Fraction(1,3);

$mathOperation = new Math();

$mathOperation->add($fractionOne, $fractionTwo);
$mathOperation->subtract($fractionOne, $fractionTwo);
$mathOperation->multiply($fractionOne, $fractionTwo);
$mathOperation->divide($fractionOne, $fractionTwo);
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 70% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~30 days

Recently: every ~44 days

Total

7

Last Release

2916d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fbc9ce9bf4321141561d259bf24ba28ee614592af9a8c4f2cef82cf32f5760ee?d=identicon)[xxaxxo](/maintainers/xxaxxo)

---

Top Contributors

[![michael-kumar](https://avatars.githubusercontent.com/u/41955365?v=4)](https://github.com/michael-kumar "michael-kumar (14 commits)")[![xxaxxo](https://avatars.githubusercontent.com/u/1206043?v=4)](https://github.com/xxaxxo "xxaxxo (6 commits)")

---

Tags

mathfractionxxaxxoxxc

### Embed Badge

![Health badge](/badges/xxc-fractionmath/health.svg)

```
[![Health](https://phpackages.com/badges/xxc-fractionmath/health.svg)](https://phpackages.com/packages/xxc-fractionmath)
```

###  Alternatives

[brick/math

Arbitrary-precision arithmetic library

2.1k504.0M277](/packages/brick-math)[markrogoyski/math-php

Math Library for PHP. Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra

2.4k7.1M40](/packages/markrogoyski-math-php)[phpseclib/bcmath_compat

PHP 5.x-8.x polyfill for bcmath extension

16720.7M17](/packages/phpseclib-bcmath-compat)[rubix/tensor

A library and extension that provides objects for scientific computing in PHP.

2751.4M5](/packages/rubix-tensor)[jlawrence/eos

Parse and solve math equations without using 'eval()'.

1071.1M11](/packages/jlawrence-eos)[php-decimal/php-decimal

Correctly-rounded arbitrary precision decimal floating point

781.0M9](/packages/php-decimal-php-decimal)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
