# std.math: add nextAfter \(\#16894\) · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/ad6f8e3a5955df4d26478bc284919f4e5c8a6913)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: ad6f8e3a5955df4d26478bc284919f4e5c8a6913

Requested commit: ad6f8e3a5955df4d26478bc284919f4e5c8a6913

Commit: ad6f8e3a5955df4d26478bc284919f4e5c8a6913

Tree: 3877a9c1b0b2d5b5f198da70fd83cb9412882127

Author: castholm

Committer: GitHub

## Message

```
std.math: add nextAfter (#16894)

`nextAfter()` returns the next representable value after `x` in the direction of `y` and is a standard math library function ([C++](https://en.cppreference.com/w/cpp/numeric/math/nextafter), [Java](https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#nextAfter-double-double-)). It is primarily useful for bitwise incrementing/decrementing floats.

This implementation supports runtime integers, runtime floats and `comptime_int`. `comptime_float` is not supported because NaNs/infinities are intentionally difficult to obtain and because I'm not sure if the fact that it's backed by `f128` is supposed to be an implementation detail. Either way, the user could just call the function with the floating-point type whose behavior they want at comptime and then cast the result to `comptime_float`.

The float implementation was ported from mingw-w64 with some slight changes made possible because the Zig standard library doesn't care about raising FP exceptions.

The number of test cases may seem excessive but they should cover every normal and edge case for every float type and are especially important for verifying that `f80` works.
```

## Parents

- [e6590fea19e3eab94b35bfd3c36e29b53cefcaaf](https://git.cafe/gitcafe/zig/commit/e6590fea19e3eab94b35bfd3c36e29b53cefcaaf?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/ad6f8e3a5955df4d26478bc284919f4e5c8a6913?format=markdown)
