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
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...
#18: Post edited
- 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
- 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
- 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
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
- 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
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
Uniform floating point from unsigned integer
- Uniform floating point U[0, 1] from unsigned integer
#11: Post edited
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.
#9: Post edited
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
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
- 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
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
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
- 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
- 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
- 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
- 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.
