PHPackages                             nsfisis/next-after - 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. nsfisis/next-after

ActiveLibrary

nsfisis/next-after
==================

PHP port of java.lang.Math.nextAfter() family

1.1.0(3mo ago)051MITPHPPHP &gt;=8.4CI passing

Since Oct 18Pushed 3mo agoCompare

[ Source](https://github.com/nsfisis/php-next-after)[ Packagist](https://packagist.org/packages/nsfisis/next-after)[ Docs](https://github.com/nsfisis/php-next-after)[ RSS](/packages/nsfisis-next-after/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (4)Used By (1)

php-next-after
==============

[](#php-next-after)

[![Packagist](https://camo.githubusercontent.com/dc777d97f08eb5bc026d7dfcc5a833baf5fdba191e813c70af7dd3da479c5058/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e7366697369732f6e6578742d6166746572)](https://packagist.org/packages/nsfisis/next-after)[![Test](https://github.com/nsfisis/php-next-after/actions/workflows/test.yaml/badge.svg)](https://github.com/nsfisis/php-next-after/actions/workflows/test.yaml)

A PHP library that provides a port of Java's `Math.nextAfter()` family of functions.

Overview
--------

[](#overview)

This library implements IEEE 754 floating-point manipulation functions that return the next representable floating-point number in a given direction:

- `nextAfter($x, $y)` - Returns the adjacent float in the direction of another value
- `nextUp($x)` - Returns the next float toward positive infinity
- `nextDown($x)` - Returns the next float toward negative infinity

Requirements
------------

[](#requirements)

- PHP 8.4 or higher
- Little-endian 64-bit integers
- IEEE 754 double-precision floats (binary64)

The library performs runtime assertions to verify these constraints are met on the current system.

Installation
------------

[](#installation)

```
$ composer require nsfisis/next-after
```

Exapmles
--------

[](#exapmles)

```
use Nsfisis\NextAfter\NextAfter;

// Get the next representable float after 1.0.
$next = NextAfter::nextAfter(1.0, 2.0); // => 1.0000000000000002

// Get the next float toward positive infinity.
$up = NextAfter::nextUp(1.0); // => 1.0000000000000002

// Get the next float toward negative infinity.
$down = NextAfter::nextDown(1.0); // => 0.9999999999999999
```

API Reference
-------------

[](#api-reference)

### `nextAfter(float $x, float $y): float`

[](#nextafterfloat-x-float-y-float)

Returns the floating-point number adjacent to `$x` in the direction of `$y`. If `$x` equals `y`, returns `y`.

#### Special Cases

[](#special-cases)

- If either argument is NaN, the result is NaN
- If both arguments equal, `$y` is returned as it is
- If `$x` is `minValue()` and `$y` is greater than `$x`, the result is positive zero
- If `$x` is `-minValue()` and `$y` is less than `$x`, the result is negative zero
- If `$x` is infinity and `$y` is not, `PHP_FLOAT_MAX` is returned
- If `$x` is negative infinity and `$y` is not, `-PHP_FLOAT_MAX` is returned
- If `$x` is `PHP_FLOAT_MAX` and `$y` is infinity, infinity is returned
- If `$x` is `-PHP_FLOAT_MAX` and `$y` is negative infinity, negative infinity is returned

### `nextUp(float $x): float`

[](#nextupfloat-x-float)

Returns the floating-point number adjacent to `$x` in the direction of positive infinity.

This is semantically equivalent to `nextAfter($x, INF)`.

#### Special Cases

[](#special-cases-1)

- If `$x` is NaN, the result is NaN
- If `$x` is positive infinity, the result is positive infinity
- If `$x` is zero, the result is `minValue()`
- If `$x` is `-minValue()`, the result is negative zero
- If `$x` is `PHP_FLOAT_MAX`, infinity is returned

### `nextDown(float $x): float`

[](#nextdownfloat-x-float)

Returns the floating-point number adjacent to `$x` in the direction of negative infinity.

This is semantically equivalent to `nextAfter($x, -INF)`.

#### Special Cases

[](#special-cases-2)

- If `$x` is NaN, the result is NaN
- If `$x` is negative infinity, the result is negative infinity
- If `$x` is zero, the result is `-minValue()`
- If `$x` is `minValue()`, the result is positive zero
- If `$x` is `-PHP_FLOAT_MAX`, negative infinity is returned

### `minValue(): float`

[](#minvalue-float)

Returns the minimum representable non-zero floating-point number. Note that this is a subnormal number and is not the same as `PHP_FLOAT_MIN`, which is the smallest *normal* number.

License
-------

[](#license)

See the [LICENSE](./LICENSE) file.

Credits
-------

[](#credits)

This library is a PHP port of Java's `java.lang.Math.nextAfter()`, `nextUp()`, and `nextDown()` methods.

Reference: [Java Math Documentation](https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html)

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance82

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~60 days

Total

3

Last Release

92d ago

Major Versions

0.1.0 → 1.0.02025-10-18

PHP version history (2 changes)0.1.0PHP &gt;=8.3

1.1.0PHP &gt;=8.4

### Community

Maintainers

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

---

Top Contributors

[![nsfisis](https://avatars.githubusercontent.com/u/54318333?v=4)](https://github.com/nsfisis "nsfisis (16 commits)")

---

Tags

float

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nsfisis-next-after/health.svg)

```
[![Health](https://phpackages.com/badges/nsfisis-next-after/health.svg)](https://phpackages.com/packages/nsfisis-next-after)
```

###  Alternatives

[nelexa/buffer

Reading And Writing Binary Data (incl. primitive types, ex. byte, ubyte, short, ushort, int, uint, long, float, double). The classes also help with porting the I/O operations of the JAVA code.

33521.7k4](/packages/nelexa-buffer)[cviebrock/eloquent-typecast

Trait for Eloquent models to force type-casting on retrieved values

2468.0k](/packages/cviebrock-eloquent-typecast)[fisharebest/laravel-floats

Floating point support for Laravel migrations

1111.4k](/packages/fisharebest-laravel-floats)[danog/phpstruct

PHP implementation of python's struct module.

1110.1k](/packages/danog-phpstruct)

PHPackages © 2026

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