Skip to content

Commit 0c49fc4

Browse files
authored
[libc][math] Implement nexttoward functions (#72763)
Implements the `nexttoward`, `nexttowardf` and `nexttowardl` functions. Also, raise excepts required by the standard in `nextafter` functions. cc: @lntue
1 parent f79676a commit 0c49fc4

26 files changed

+553
-5
lines changed

libc/config/darwin/arm/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ set(TARGET_LIBM_ENTRYPOINTS
199199
libc.src.math.nextafter
200200
libc.src.math.nextafterf
201201
libc.src.math.nextafterl
202+
libc.src.math.nexttoward
203+
libc.src.math.nexttowardf
204+
libc.src.math.nexttowardl
202205
libc.src.math.powf
203206
libc.src.math.remainderf
204207
libc.src.math.remainder

libc/config/darwin/x86_64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ set(TARGET_LIBM_ENTRYPOINTS
178178
#libc.src.math.nextafter
179179
#libc.src.math.nextafterf
180180
#libc.src.math.nextafterl
181+
#libc.src.math.nexttoward
182+
#libc.src.math.nexttowardf
183+
#libc.src.math.nexttowardl
181184
#libc.src.math.remainderf
182185
#libc.src.math.remainder
183186
#libc.src.math.remainderl

libc/config/gpu/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ set(TARGET_LIBM_ENTRYPOINTS
219219
libc.src.math.nearbyintf
220220
libc.src.math.nextafter
221221
libc.src.math.nextafterf
222+
libc.src.math.nexttoward
223+
libc.src.math.nexttowardf
222224
libc.src.math.pow
223225
libc.src.math.powf
224226
libc.src.math.remainder

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ set(TARGET_LIBM_ENTRYPOINTS
316316
libc.src.math.nextafter
317317
libc.src.math.nextafterf
318318
libc.src.math.nextafterl
319+
libc.src.math.nexttoward
320+
libc.src.math.nexttowardf
321+
libc.src.math.nexttowardl
319322
libc.src.math.powf
320323
libc.src.math.remainderf
321324
libc.src.math.remainder

libc/config/linux/riscv/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ set(TARGET_LIBM_ENTRYPOINTS
325325
libc.src.math.nextafter
326326
libc.src.math.nextafterf
327327
libc.src.math.nextafterl
328+
libc.src.math.nexttoward
329+
libc.src.math.nexttowardf
330+
libc.src.math.nexttowardl
328331
libc.src.math.powf
329332
libc.src.math.remainderf
330333
libc.src.math.remainder

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ set(TARGET_LIBM_ENTRYPOINTS
329329
libc.src.math.nextafter
330330
libc.src.math.nextafterf
331331
libc.src.math.nextafterl
332+
libc.src.math.nexttoward
333+
libc.src.math.nexttowardf
334+
libc.src.math.nexttowardl
332335
libc.src.math.powf
333336
libc.src.math.remainderf
334337
libc.src.math.remainder

libc/config/windows/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ set(TARGET_LIBM_ENTRYPOINTS
198198
libc.src.math.nextafter
199199
libc.src.math.nextafterf
200200
libc.src.math.nextafterl
201+
libc.src.math.nexttoward
202+
libc.src.math.nexttowardf
203+
libc.src.math.nexttowardl
201204
libc.src.math.powf
202205
libc.src.math.remainderf
203206
libc.src.math.remainder

libc/docs/math/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ Basic Operations
230230
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
231231
| nextafterl | |check| | |check| | | |check| | |check| | | | |check| | | | | |
232232
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
233-
| nexttoward | | | | | | | | | | | | |
233+
| nexttoward | |check| | |check| | | |check| | |check| | | | |check| | | | | |
234234
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
235-
| nexttowardf | | | | | | | | | | | | |
235+
| nexttowardf | |check| | |check| | | |check| | |check| | | | |check| | | | | |
236236
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
237-
| nexttowardl | | | | | | | | | | | | |
237+
| nexttowardl | |check| | |check| | | |check| | |check| | | | |check| | | | | |
238238
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
239239
| remainder | |check| | |check| | | |check| | |check| | | | |check| | | | | |
240240
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+

libc/spec/stdc.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,10 @@ def StdC : StandardSpec<"stdc"> {
492492
FunctionSpec<"nextafter", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
493493
FunctionSpec<"nextafterl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
494494

495+
FunctionSpec<"nexttowardf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<LongDoubleType>]>,
496+
FunctionSpec<"nexttoward", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<LongDoubleType>]>,
497+
FunctionSpec<"nexttowardl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
498+
495499
FunctionSpec<"powf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
496500
FunctionSpec<"pow", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
497501

libc/src/__support/FPUtil/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ add_header_library(
9696
HDRS
9797
ManipulationFunctions.h
9898
DEPENDS
99+
.fenv_impl
99100
.fp_bits
100101
.nearest_integer_operations
101102
.normal_float

0 commit comments

Comments
 (0)