File tree 1 file changed +8
-4
lines changed
libc/src/__support/FPUtil 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -144,10 +144,11 @@ LIBC_INLINE T ldexp(T x, int exp) {
144
144
return normal ;
145
145
}
146
146
147
- template <
148
- typename T, typename U,
149
- cpp::enable_if_t <cpp::is_floating_point_v<T> && cpp::is_floating_point_v<U>,
150
- int > = 0 >
147
+ template <typename T, typename U,
148
+ cpp::enable_if_t <cpp::is_floating_point_v<T> &&
149
+ cpp::is_floating_point_v<U> &&
150
+ (sizeof (T) <= sizeof (U)),
151
+ int > = 0 >
151
152
LIBC_INLINE T nextafter (T from, U to) {
152
153
FPBits<T> from_bits (from);
153
154
if (from_bits.is_nan ())
@@ -157,6 +158,9 @@ LIBC_INLINE T nextafter(T from, U to) {
157
158
if (to_bits.is_nan ())
158
159
return static_cast <T>(to);
159
160
161
+ // NOTE: This would work only if `U` has a greater or equal precision than
162
+ // `T`. Otherwise `from` could loose its precision and the following statement
163
+ // could incorrectly evaluate to `true`.
160
164
if (static_cast <U>(from) == to)
161
165
return static_cast <T>(to);
162
166
You can’t perform that action at this time.
0 commit comments