[LLVMdev] [RFC] Add a scaled number class (was: Add a simple soft-float class)

Sean Silva chisophugis at gmail.com
Sun Jun 22 09:56:19 PDT 2014


On Sun, Jun 22, 2014 at 1:48 AM, James Courtier-Dutton <
james.dutton at gmail.com> wrote:

> On 21 June 2014 00:40, Sean Silva <chisophugis at gmail.com> wrote:
> >
> >
> > my 2c: describe it as "an approximate, high-dynamic-range unsigned
> integer".
> >
> > That doesn't lend itself to something easy to type, but "ApproxHDRUint"
> > might be doable. Plus, it sounds sort of scary.
> >
> > Having something in the name that suggests that it is an integer should
> ward
> > off any attempt to use it for numerics.
> >
> > -- Sean Silva
> >
>
> I would suggest that "high-dynamic-range" is also the wrong word. It
> is not actually providing any extra dynamic range.
>

Dynamic range is the ratio between the largest and smallest representable
value (see http://en.wikipedia.org/wiki/Dynamic_range). So yes it does
provide more dynamic range; in fact, pretty much the entire purpose of
using floating point numbers is to extend the dynamic range (see
http://en.wikipedia.org/wiki/Floating_point).

What changes is the distribution of the numbers; they are no longer
uniformly distributed (see Knuth 4.2.4 "Distribution of Floating Point
Numbers" or google for "distribution of floating point numbers").

-- Sean Silva


> Having something that can go from 0 to 20 in steps of 2 has no better
> dynamic range as something that can go from 0 to 10 in steps of 1.
> Simply calling it "scaled unsigned integer" is more accurate.
> Or "unsigned integer with scale factor".
>
> I think it would also be a good idea to explain what maths operations
> you are likely to want to do.
> For example, if the number is 20, with scale factor 2, and you add 1
> with scale factor 1 to it, the answer is undefined.
> If all you are going to do is somehow reach a value and then is won't
> change, and the only operations you are going to do are "compare"
> operations, then that is something that is easier to understand for
> other programmers.
>
> Just out of curiosity, what is the requirement or use case that is
> driving a "scaled unsigned integer" instead of say just using an
> integer with more bits.
>
> James
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140622/12956ff2/attachment.html>


More information about the llvm-dev mailing list