Page MenuHomePhabricator

[Fixed Point Arithmetic] Conversion between Fixed Point and Floating Point Numbers
AbandonedPublic

Authored by leonardchan on May 15 2018, 7:58 PM.

Details

Summary

This patch has the implementation and tests for converting between fixed point and floating point numbers.

The conversion process is simply dividing the fixed point value, as an integer, by 2^(# of fractional bits) as a float.

float f = (float)2.5k;
assert(f > 2.4999 && f < 2.5001);  // High precision since the fractional value can be evenly
                                                          // represented.

Diff Detail

Repository
rC Clang

Event Timeline

leonardchan created this revision.May 15 2018, 7:58 PM
leonardchan edited the summary of this revision. (Show Details)
leonardchan retitled this revision from Conversion between Fixed Point and Floating Point Numbers to [Fixed Point Arithmetic] Conversion between Fixed Point and Floating Point Numbers.May 16 2018, 9:42 AM
scanon requested changes to this revision.May 22 2018, 7:06 AM
scanon added a subscriber: scanon.

IIRC the optimization of divide-by-power-of-two --> multiply-by-inverse does not occur at -O0, so it would be better to multiply by 2^(-fbits) instead.

This revision now requires changes to proceed.May 22 2018, 7:06 AM
Ka-Ka added a subscriber: Ka-Ka.May 23 2018, 1:09 AM
leonardchan abandoned this revision.Jun 21 2018, 2:45 PM

The logic in this patch is moved to https://reviews.llvm.org/D48456