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

Robinson, Paul Paul_Robinson at playstation.sony.com
Mon Jun 23 10:59:41 PDT 2014


> -----Original Message-----
> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On
> Behalf Of James Courtier-Dutton
>
> 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.

"Undefined" is too strong a term here.  Typically with scaled arithmetic
you'd do all operations in a sufficiently wide representation that you
compute the correct pure numerical result, and then possibly modify
that result as needed (may include rounding) to match the desired output 
scale.  You can do the operations with narrower representations if you 
can prove that the scaled result would be unaffected.

That is: adding 10 to 0.1 and asking for an integer result is not an 
undefined operation; it will yield the well-defined value 10.

> 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.

It's more compact, and often the low-order bits of a large result are
not particularly relevant.
--paulr






More information about the llvm-dev mailing list