| 4 Jun 2026 |
alexfmpe | It might be 'increment the exponent' or it might be a completely different mantissa with a completely different exponent | 11:28:59 |
alexfmpe | Imagine computing the 'next rational' when denominator and numerator only go up to 2^32 or whatever | 11:29:38 |
alexfmpe | For floats it's similar to that but instead of quotients you're dealing with exponentiation | 11:30:14 |
piegames | @alexfmpe:matrix.org those are orthogonal concerns to the original question. And yes, this is computable, and commonly provided by libraries under the name "nextafter" | 11:41:18 |
alexfmpe | Well sure you can compute it, it's just not obvious to me how to do it efficiently since there's essentially two knobs to turn in the binary representation | 11:49:23 |
alexfmpe | Sure, "nextafter" probably does it efficiently | 11:50:24 |
Sergei Zimmerman (xokdvium) | Don't think there's an efficient hack to split a double into its significand/exponent | 11:54:48 |
Sergei Zimmerman (xokdvium) | Reconstructing it should be quite easy | 11:55:15 |
alexfmpe | Wonder if you can do newton's method. Make a finite guess, average the guess and original number, make that the new guess and repeat until the output is one of the inputs | 12:02:36 |
alexfmpe | It's kinda binary search, so proporcional to number of bits or something, not great not terrible | 12:03:02 |
alexfmpe | er, more like quadratic since O(n) operations with N bits | 12:03:30 |
Sergei Zimmerman (xokdvium) | Hm yeah the exponent range is small | 12:03:39 |
Sergei Zimmerman (xokdvium) | It's just 11 bits | 12:03:49 |
alexfmpe | But we treat word size as O(1) in practice | 12:03:55 |
alexfmpe | In reply to @xokdvium:matrix.org Hm yeah the exponent range is small Well I'm not leveraging anything about the binary structure here | 12:04:18 |
alexfmpe | You won't enumerate all floats by just enumerating the exponent | 12:04:34 |
alexfmpe | So at some point 'nextafter' has to touch the mantissa | 12:04:47 |
Sergei Zimmerman (xokdvium) | But to get the nextafter you just +1 to the mantissa's binary representation | 12:05:18 |
alexfmpe | Why? | 12:05:31 |
alexfmpe | Also this is super offtopic, maybe continue in a thread? | 12:05:50 |
Sergei Zimmerman (xokdvium) | (Or increment the exponent if the mantissa would overflow) | 12:05:51 |
Sergei Zimmerman (xokdvium) | Sure | 12:06:06 |
alexfmpe | Why is incrementing the mantissa expected to always yield a smaller number than incrementing the exponent? | 12:07:23 |
alexfmpe | Increasing the base of a large exponent should yield greater increases than the large exponent | 12:08:32 |
alexfmpe | 2^4=16
2^5=32
3^4=81 | 12:09:02 |
alexfmpe | It's a 2D thing, no way around it | 12:09:26 |
Sergei Zimmerman (xokdvium) | I mean, you want to increment by 1 ulp https://en.wikipedia.org/wiki/Unit_in_the_last_place | 12:10:46 |
Sergei Zimmerman (xokdvium) | There's a different with subnormals, since the exponent is computed differently | 12:11:29 |
Sergei Zimmerman (xokdvium) | https://github.com/boostorg/math/blob/febada30785cb1e5ffb61d817e7d1a4b8985e544/include/boost/math/special_functions/next.hpp#L206-L209 | 12:14:35 |
| @lumi:the-apothecary.club changed their profile picture. | 12:17:44 |