Hi Greg,
All good. I think you described it fine. The question I had was more on what the big picture was. Why do it at all?
And yes, there’d be a way to manipulate the bits to manually construct it, but in most languages, that’d be pretty ugly anyway.
Regards,
Greg
Dr Greg Low
1300SQLSQL (1300 775 775) office | +61 419201410 mobile
SQL Down Under | Web: https://sqldownunder.com
| About Greg:
https://about.me/greg.low
From: Greg Keogh <gfkeogh@gmail.com>
Sent: Tuesday, 5 July 2022 8:58 AM
To: Dr Greg Low <greg@sqldownunder.com>
Cc: ozDotNet <ozdotnet@ozdotnet.com>
Subject: Re: 53-bit double
I might have missed it earlier Greg but was the actual problem that this helps with? I was intrigued by the underlying problem.
I didn't express myself clearly originally. I was trying to convert a 64-bit random integer into a double and guarantee that all possible 2^53 floating values in the range 0 to 1 could result. Someone suggested that weird bit of earlier incomprehensible
code, but it turns out a simple shift-and-multiply does that trick.
There are lots of modern PRNGs that generate 64-bits, like the xoroshift** that is being used in the latest Random class. But how do you convert 64-bits "perfectly" into doubles? I finally confirmed a correct way.
I'm still wondering if there is a way of manually constructing an IEEE 754 number from the raw bits, but it makes my head hurt.
Cheers, GK