Download the PHP package lamansky/fraction without Composer

On this page you can find all versions of the php package lamansky/fraction. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package fraction

Fraction

A PHP class that represents a fraction. Converts to/from floats (0.25 ↔ ¼), simplifies fractions (⁴⁄₈ → ½), handles mathematical operations (½ + ⅓), supports negative fractions (−⅘), and does Unicode string output. Requires PHP 7.1 or above.

Installation

With Composer installed on your computer and initialized for your project, run this command in your project’s root directory:

Requires PHP 7.1 or above.

API

The library consists of a single class: Lamansky\Fraction\Fraction.

Constructor Parameters

  1. $a (int or float): The numerator of the fraction (the number on top).
  2. $b (int or float): The denominator of the fraction (the number on bottom).
  3. Optional: $negative (bool or int): If set to true or -1 (or any negative number), the fraction will be negative. If set to false or 1 (or any positive number), the fraction will be positive. If omitted, the fraction will be negative only if $a or $b is negative (but not both). If provided, the value of $negative will override whatever sign values $a or $b may have.

Static Method: fromFloat () : Fraction

Accepts one parameter (a float number) and returns a Fraction. The Fraction will have the same sign value (positive/negative) as the float.

isNegative () : bool

No parameters. Returns true if the fraction is negative; otherwise false.

getSignMultiplier () : int

No parameters. Returns -1 if the fraction is negative, or 1 if it is positive.

getNumerator () : int

No parameters. Returns the numerator of the fraction (the number on top).

getMixedInteger () : int

No parameters. Returns the integer component of a mixed fraction. A mixed fraction is one which is simplified to use a whole number (e.g. ⁵⁄₄ → 1¼). Example:

If the fraction is not mixed (i.e. if the numerator is smaller than the denominator), this function will return 0.

getMixedNumerator () : int

No parameters. Returns the numerator of a mixed fraction. A mixed fraction is one which is simplified to use a whole number (e.g. ⁵⁄₄ → 1¼). Example:

If the fraction is not mixed (i.e. if the numerator is smaller than the denominator), this function will return the normal numerator.

getDenominator () : int

No parameters. Returns the denominator of the fraction (the number on bottom).

getParts () : array

No parameters. Returns an array with two elements: the numerator and the denominator.

getMixedParts () : array

No parameters. Returns an array with three elements: the mixed-fraction integer, the mixed-fraction numerator, and the denominator. For example: for the fraction 2¼, it would return [2, 1, 4].

toString () : string

No parameters. Returns an ASCII string representation of the fraction.

toUnicodeString () : string

No parameters. Returns a Unicode string representation of the fraction.

toFloat () : float

No parameters. Divides the numerator by the denominator and returns a floating-point number.

clone () : Fraction

No parameters. Returns a Fraction with the same numerator, denominator, and positive/negative sign.

absolute () : Fraction

No parameters. Clones the Fraction, but makes it positive if it’s negative.

add (Fraction $other) : Fraction

Returns a Fraction that is the sum of the current fraction and $other.

Note that if $other is a negative fraction, this will end up being subtraction (just like in math).

subtract (Fraction $other) : Fraction

Subtracts $other from the current fraction and returns the result.

multiply (Fraction $other) : Fraction

Multiplies the current fraction by $other and returns the result.

divide (Fraction $other) : Fraction

Divides the current fraction by $other and returns the result.

Unit Tests

To run the development test suite, execute this command:


All versions of fraction with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lamansky/fraction contains the following files

Loading the files please wait ....