Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

60%
+4 −2
Q&A Uniform floating point from unsigned integer

How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats in [0, 1]? By uniform, I mean the continuous unif...

1 answer  ·  posted 8mo ago by deleted user  ·  last activity 7mo ago by Monica Cellio‭

Question integer floating-point sampling
#20: Post undeleted by user avatar Monica Cellio‭ · 2026-02-12T15:32:09Z (7 months ago)
#19: Post deleted by (deleted user) · 2026-02-11T19:39:27Z (7 months ago)
#18: Post edited by (deleted user) · 2026-02-11T17:39:15Z (7 months ago)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats in [0, 1]? By uniform, I mean the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). All bounds are inclusive.
  • It needs to be accurate enough for stats/ML.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
  • NB. I assume I can scale [0, 1] to [a, b] as `samples * (a - b) + b` since that's [what XLA does](https://github.com/openxla/xla/blob/ca1fb0cba713ac87b536476d93447f98c1d5e1f5/xla/hlo/builder/lib/prng.cc#L576)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats in [0, 1]? By uniform, I mean the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). All bounds are inclusive.
  • It needs to be accurate enough for stats/ML.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
  • NB. I assume I can scale [0, 1] to [a, b] as `samples * (a - b) + b` since that's [what XLA does](https://github.com/openxla/xla/blob/ca1fb0cba713ac87b536476d93447f98c1d5e1f5/xla/hlo/builder/lib/prng.cc#L576) (though I will have to be careful about overflow).
#17: Post edited by (deleted user) · 2026-02-10T02:22:07Z (7 months ago)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats in [0, 1]? By uniform, I mean the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). All bounds are inclusive.
  • It needs to be accurate enough for stats/ML.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
  • I assume I can scale [0, 1] to [a, b] as `samples * (a - b) + b` since that's [what XLA does](https://github.com/openxla/xla/blob/ca1fb0cba713ac87b536476d93447f98c1d5e1f5/xla/hlo/builder/lib/prng.cc#L576)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats in [0, 1]? By uniform, I mean the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). All bounds are inclusive.
  • It needs to be accurate enough for stats/ML.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
  • NB. I assume I can scale [0, 1] to [a, b] as `samples * (a - b) + b` since that's [what XLA does](https://github.com/openxla/xla/blob/ca1fb0cba713ac87b536476d93447f98c1d5e1f5/xla/hlo/builder/lib/prng.cc#L576)
#16: Post edited by (deleted user) · 2026-02-08T21:14:49Z (7 months ago)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats in [0, 1]? By uniform, I mean the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). All bounds are inclusive.
  • It needs to be accurate enough for stats/ML.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
  • I am assuming I can scale [0, 1] to [a, b] as `samples * (a - b) + b` since that's [what XLA does](https://github.com/openxla/xla/blob/ca1fb0cba713ac87b536476d93447f98c1d5e1f5/xla/hlo/builder/lib/prng.cc#L576)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats in [0, 1]? By uniform, I mean the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). All bounds are inclusive.
  • It needs to be accurate enough for stats/ML.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
  • I assume I can scale [0, 1] to [a, b] as `samples * (a - b) + b` since that's [what XLA does](https://github.com/openxla/xla/blob/ca1fb0cba713ac87b536476d93447f98c1d5e1f5/xla/hlo/builder/lib/prng.cc#L576)
#15: Post edited by (deleted user) · 2026-02-08T21:14:11Z (7 months ago)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats in [a, b] for user-specified `a`, `b`? By uniform, I mean the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). All bounds are inclusive.
  • It needs to be accurate enough for stats/ML.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats in [0, 1]? By uniform, I mean the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). All bounds are inclusive.
  • It needs to be accurate enough for stats/ML.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
  • I am assuming I can scale [0, 1] to [a, b] as `samples * (a - b) + b` since that's [what XLA does](https://github.com/openxla/xla/blob/ca1fb0cba713ac87b536476d93447f98c1d5e1f5/xla/hlo/builder/lib/prng.cc#L576)
#14: Post edited by (deleted user) · 2026-02-07T03:26:25Z (7 months ago)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats in [a, b] for user-specified `a`, `b`? By uniform, I mean the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). All bounds are inclusive.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats in [a, b] for user-specified `a`, `b`? By uniform, I mean the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). All bounds are inclusive.
  • It needs to be accurate enough for stats/ML.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
#13: Post edited by (deleted user) · 2026-02-07T03:14:36Z (7 months ago)
  • Uniform floating point U[0, 1] from unsigned integer
  • Uniform floating point from unsigned integer
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats in [0, 1]? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). All bounds are inclusive.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats in [a, b] for user-specified `a`, `b`? By uniform, I mean the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). All bounds are inclusive.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
#12: Post edited by (deleted user) · 2026-02-06T23:18:37Z (7 months ago)
  • Uniform floating point from unsigned integer
  • Uniform floating point U[0, 1] from unsigned integer
#11: Post edited by (deleted user) · 2026-02-06T23:18:08Z (7 months ago)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). Eventually samples will be bound between user-specified bounds, U[a, b]. Since I can scale to that from samples over the whole range of possible floats [min, max], either U[a, b] or U[min, max] is helpful. All bounds are inclusive.
  • I'd prefer no infinities or NaN, but they're not the end of the world.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats in [0, 1]? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). All bounds are inclusive.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
#10: Question reopened by user avatar Karl Knechtel‭ · 2026-02-05T16:24:56Z (7 months ago)
#9: Post edited by (deleted user) · 2026-02-05T15:07:00Z (7 months ago)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). Eventually samples will be bound between user-specified bounds, U[a, b]. Since I can scale to that from samples over the whole range of possible floats [min, max], either U[a, b] or U[min, max] is helpful.
  • I'd prefer no infinities or NaN, but they're not the end of the world.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). Eventually samples will be bound between user-specified bounds, U[a, b]. Since I can scale to that from samples over the whole range of possible floats [min, max], either U[a, b] or U[min, max] is helpful. All bounds are inclusive.
  • I'd prefer no infinities or NaN, but they're not the end of the world.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
#8: Post edited by (deleted user) · 2026-02-05T15:02:08Z (7 months ago)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). Eventually samples will be bound between user-specified bounds, U[a, b]. Since I can scale to that from samples over the whole range of possible floats [min, max], either U[a, b] or U[min, max] is helpful.
  • I'd prefer no infinities or NaN, but they're not the end of the world.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers (over the whole range of integers) into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). Eventually samples will be bound between user-specified bounds, U[a, b]. Since I can scale to that from samples over the whole range of possible floats [min, max], either U[a, b] or U[min, max] is helpful.
  • I'd prefer no infinities or NaN, but they're not the end of the world.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
#7: Post edited by (deleted user) · 2026-02-05T15:01:08Z (7 months ago)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). Eventually samples will be bound between user-specified bounds, U[a, b]. Since I can scale to that from samples over the whole range of possible floats [min, max], either U[a, b] or U[min, max] is helpful.
  • I'd prefer no infinities or NaN, but they're not the end of the world.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note that API can bitcast naively to float, and cast to float using the (approx) numerical value.
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). Eventually samples will be bound between user-specified bounds, U[a, b]. Since I can scale to that from samples over the whole range of possible floats [min, max], either U[a, b] or U[min, max] is helpful.
  • I'd prefer no infinities or NaN, but they're not the end of the world.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note this API can bitcast naively to float (i.e. reinterpret bits as they are as a float), and cast to float using the (approx) numerical value.
#6: Post edited by (deleted user) · 2026-02-05T15:00:03Z (7 months ago)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). Eventually samples will be bound between user-specified bounds, U[a, b]. Since I can scale to that from samples over the whole range of possible floats [min, max], I'm happy for either U[a, b] or U[min, max].
  • I'd prefer no infinities or NaN, but they're not the end of the world.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note that API can bitcast naively to float, and cast to float using the (approx) numerical value.
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). Eventually samples will be bound between user-specified bounds, U[a, b]. Since I can scale to that from samples over the whole range of possible floats [min, max], either U[a, b] or U[min, max] is helpful.
  • I'd prefer no infinities or NaN, but they're not the end of the world.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note that API can bitcast naively to float, and cast to float using the (approx) numerical value.
#5: Post edited by (deleted user) · 2026-02-05T14:59:14Z (7 months ago)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution).
  • I'd prefer no infinities or NaN, but don't care too much since they're so unlikely.
  • I have to hand ops like add, subtract, divide, multiply, modulo, as well as standard bit ops, and bitcast naively to float. I can also cast to float using the (approx) numerical value. I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an equivalent answer in basically any language with these types would suffice.
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution). Eventually samples will be bound between user-specified bounds, U[a, b]. Since I can scale to that from samples over the whole range of possible floats [min, max], I'm happy for either U[a, b] or U[min, max].
  • I'd prefer no infinities or NaN, but they're not the end of the world.
  • I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an answer in e.g. C with equivalent maths and bit ops would be trivial to translate. Note that API can bitcast naively to float, and cast to float using the (approx) numerical value.
#4: Post edited by (deleted user) · 2026-02-04T21:59:08Z (8 months ago)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution).
  • I'd prefer no infinities or NaN, but don't care too much since they're so unlikely.
  • I have to hand ops like add, subtract, divide, multiply, modulo, as well as standard bit ops, and bitcast naively to float. I can also cast to float using the (approx) numerical value. I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an equivalent answer in basically any language with these types would suffice.
  • I know I can cast to float, divide by `uintmax`, and multiply by the float range, but I'm concerned that will introduce bias around integers.
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution).
  • I'd prefer no infinities or NaN, but don't care too much since they're so unlikely.
  • I have to hand ops like add, subtract, divide, multiply, modulo, as well as standard bit ops, and bitcast naively to float. I can also cast to float using the (approx) numerical value. I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an equivalent answer in basically any language with these types would suffice.
#3: Post edited by (deleted user) · 2026-02-04T21:50:15Z (8 months ago)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution).
  • I'd prefer no infinities or NaN, but don't care too much since they're so unlikely.
  • I have to hand ops like add, subtract, divide, multiply, modulo, as well as standard bit ops, and bitcast naively to float. I can also cast to float using the (approx) numerical value. I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an equivalent answer is basically any language would suffice.
  • I know I can cast to float, divide by `uintmax`, and multiply by the float range, but I'm concerned that will introduce bias around integers.
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution).
  • I'd prefer no infinities or NaN, but don't care too much since they're so unlikely.
  • I have to hand ops like add, subtract, divide, multiply, modulo, as well as standard bit ops, and bitcast naively to float. I can also cast to float using the (approx) numerical value. I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an equivalent answer in basically any language with these types would suffice.
  • I know I can cast to float, divide by `uintmax`, and multiply by the float range, but I'm concerned that will introduce bias around integers.
#2: Post edited by (deleted user) · 2026-02-04T21:49:48Z (8 months ago)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution).
  • I'd prefer no infinities or NaN, but don't care too much since they're so unlikely.
  • I have to hand ops like add, subtract, divide, multiply, modulo, as well as standard bit ops, and bitcast naively to float. I can also cast to float using the (approx) numerical value. I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an equivalent answer is basically any language would suffice.
  • I know I can cast to float, divide by `uintmax`, and multiply by the float range, but I'm concerned that will introduce bias to integers.
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution).
  • I'd prefer no infinities or NaN, but don't care too much since they're so unlikely.
  • I have to hand ops like add, subtract, divide, multiply, modulo, as well as standard bit ops, and bitcast naively to float. I can also cast to float using the (approx) numerical value. I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an equivalent answer is basically any language would suffice.
  • I know I can cast to float, divide by `uintmax`, and multiply by the float range, but I'm concerned that will introduce bias around integers.
#1: Post edited by (deleted user) · 2026-02-04T21:47:45Z (8 months ago)
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution).
  • I'd prefer no infinities or NaN, but don't care too much since they're so unlikely.
  • I have to hand ops like add, subtract, divide, multiply, modulo, as well as standard bit ops, and bitcast naively to float. I can also cast to float using the (approx) numerical value. If you want to be specific, I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but I imagine that's pretty similar to how you'd do it in any language with bit manipulation.
  • I know I can cast to float, divide by `uintmax`, and multiply by the float range, but I'm concerned that will introduce bias to integers.
  • How can I turn uniform samples of unsigned n-bit (n=16/32/64) integers into uniform samples of n-bit IEEE floats? By uniform, I mean as in the [continuous uniform distribution](https://en.wikipedia.org/wiki/Continuous_uniform_distribution).
  • I'd prefer no infinities or NaN, but don't care too much since they're so unlikely.
  • I have to hand ops like add, subtract, divide, multiply, modulo, as well as standard bit ops, and bitcast naively to float. I can also cast to float using the (approx) numerical value. I'm using the [StableHLO API](https://openxla.org/stablehlo/spec), but an equivalent answer is basically any language would suffice.
  • I know I can cast to float, divide by `uintmax`, and multiply by the float range, but I'm concerned that will introduce bias to integers.