Download the PHP package phpcommon/intmath without Composer

On this page you can find all versions of the php package phpcommon/intmath. 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 intmath

PHPCommon IntMath

Build Status Code Coverage Scrutinizer Code Quality StyleCI Latest Stable Version Dependency Status

Latest release: 1.0.0-beta

PHP 5.3+ library for arithmetic operations on integers that wraps around upon overflow.

Attention

This library is not intended for use as a way to properly perform arithmetic operations on integers and should not be used in place of the native arithmetic operators or any other library designed for such purpose.

Unlike other languages that overflow large positive integers into large negative integers, PHP actually overflows integers to floating-point numbers. In most cases, arithmetic overflows must be treated as an unusual circumstance which requires special handling. However, there are some cases where such wrap-around behavior is actually useful - for example with TCP sequence numbers or certain algorithms, such as hash calculation. This utility class provides basic arithmetic functions that operate in accordance to that behaviour.

To illustrate, consider the following example:

As previously shown, adding one to the largest integer supported using native arithmetic operators will result in a floating-point number. By contrast, using IntMath::add() will cause an overflow, resulting in the smallest integer supported in this build of PHP.

The API is extensively documented in the source code. In addition, an HTML version is also available for more convenient viewing in browser.

Installation

Use Composer to install the package:

Operations

Currently, only the four basic arithmetic operations (addition, subtraction, multiplication and division) and negation are supported.

Negation

For integer values, negation is the same as subtraction from zero. Because PHP uses two's-complement representation for integers and the range of two's-complement values is not symmetric, the negation of the maximum negative integer results in that same maximum negative number. Despite the fact that overflow has occurred, no exception is thrown.

For all integer values $a, -$a equals (~$a) + 1.

API example usage:

Addition

The result of adding two integers is the low-order bits of the true mathematical result as represented in a sufficiently wide two's-complement format. If overflow occurs, then the sign of the result may not be the same as the sign of the mathematical sum of the two values. Despite the overflow, no exception is thrown in this case.

API example usage:

Subtraction

The subtraction of a positive number yields the same result as the addition of a negative number of equal magnitude. Furthermore, the subtraction from zero is the same as negation. The result is the low-order bits of the true mathematical result as represented in a sufficiently wide two's-complement format. If overflow occurs, then the sign of the result may not be the same as the sign of the mathematical difference of the two values. Despite the overflow, no exception is thrown in this case.

API example usage:

Multiplication

The result of multiplying two integers is the low-order bits of the true mathematical result as represented in a sufficiently wide two's-complement format. If overflow occurs, then the sign of the result may not be the same as the sign of the mathematical product of the two values. Despite the overflow, no exception is thrown in this case.

API example usage:

Division

The division rounds the result towards zero. Thus the absolute value of the result is the largest possible integer that is less than or equal to the absolute value of the quotient of the two operands. The result is zero or positive when the two operands have the same sign and zero or negative when the two operands have opposite signs.

There is one special case that does not satisfy this rule: if the dividend is the negative integer of largest possible magnitude for its type, and the divisor is -1, then integer overflow occurs and the result is equal to the dividend. Despite the overflow, no exception is thrown in this case. On the other hand if the value of the divisor in an integer division is 0, then a DivisionByZeroException is thrown.

API example usage:

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

Check out the Test Documentation for more details.

Contributing

Contributions to the package are always welcome!

Please see CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

All contents of this package are licensed under the MIT license.


All versions of intmath with dependencies

PHP Build Version
Package Version
Requires php Version ^5.3.0|^7.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 phpcommon/intmath contains the following files

Loading the files please wait ....