[libc] [llvm] [libc][math] Implement nan(f|l) functions (PR #76690)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 3 13:19:14 PST 2024


================
@@ -1055,6 +1055,38 @@ hexadecimal_string_to_float(const char *__restrict src,
   return output;
 }
 
+template <class T>
+LIBC_INLINE fputil::FPBits<T> nan_from_ncharseq(const char *__restrict ncharseq,
----------------
michaelrj-google wrote:

Yes I mean the NaN mantissa, but it's just being cast from the static `uint64_t` so we can let the caller handle that and avoid templating this function altogether.

On lower optimization levels the pointer vs the struct might make a difference, but in any practical configuration they'll be effectively identical from a performance perspective. Here's an example on godbolt so you can see the difference: https://godbolt.org/z/oMqb3r6j6
In general we try to avoid using pointers to return values because it's very error prone. It's easy to miss a value being modified if it's being passed as a pointer, especially if it's only modified sometimes. 

https://github.com/llvm/llvm-project/pull/76690


More information about the llvm-commits mailing list