Here's a thought that came up at work recently.

Is it possible to create a regex, that checks if a string can be converted to a floating point number (of fixed length) without truncation; in more exact terms, if

f32(str(x)) == x

for the language of your choice?

The answer to the naive question is yes, because the number of floats is finite, so we could just give a regex (0.0000000000001, 0.00000000000002, etc.). I'm interested in a "human-readable" regex.

So what're mathstodon's thoughts?

· · Web · 1 · 1 · 0

Actually the comparison should be str(f32(s)) == s

So really, the question is, if there's a regex that can check if a string can be safely converted to a float and back without truncation.

Sign in to participate in the conversation

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!