diff options
author | Nedeljko Babic <nedeljko.babic@imgtec.com> | 2015-05-14 16:36:36 +0300 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2015-05-14 18:00:46 +0300 |
commit | 729466dc68f9166c13be79581ecc8a79411ee885 (patch) | |
tree | 5a9eb0e0a6a480be56420cda978b421703a8d606 /libavutil | |
parent | 019daa07759727ac81f5871eb3ce582432ae483a (diff) |
libavutil/softfloat: Add test case for av_add_sf
Recently normalization (av_normalize_sf) of output was added to av_add_sf.
This normalization is used for better precision for small values and the
purpose of this (quite simple) test case is to test difference between double
and softfloat.
The values used are tailored to maximally highlighte problem with precison when
normalization is not used.
Signed-off-by: Nedeljko Babic <nedeljko.babic@imgtec.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/softfloat.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/libavutil/softfloat.c b/libavutil/softfloat.c index bf9cfda33a..b6e1f35d4d 100644 --- a/libavutil/softfloat.c +++ b/libavutil/softfloat.c @@ -26,10 +26,21 @@ #undef printf +static const SoftFloat FLOAT_0_017776489257 = {0x1234, 12}; +static const SoftFloat FLOAT_1374_40625 = {0xabcd, 25}; +static const SoftFloat FLOAT_0_1249694824218 = {0xFFF, 15}; + + +static av_const double av_sf2double(SoftFloat v) { + v.exp -= ONE_BITS +1; + if(v.exp > 0) return (double)v.mant * (double)(1 << v.exp); + else return (double)v.mant / (double)(1 << (-v.exp)); +} + int main(void){ SoftFloat one= av_int2sf(1, 0); - SoftFloat sf1, sf2; - double d1, d2; + SoftFloat sf1, sf2, sf3; + double d1, d2, d3; int i, j; av_log_set_level(AV_LOG_DEBUG); @@ -67,5 +78,21 @@ int main(void){ STOP_TIMER("softfloat add mul") } printf("test2 sf =%d (%d %d)\n", av_sf2int(sf1, 24), sf1.exp, sf1.mant); + + d1 = 0.0177764893; + d2 = 1374.40625; + d3 = 0.1249694824; + d2 += d1; + d3 += d2; + printf("test3 double: %.10lf\n", d3); + + sf1 = FLOAT_0_017776489257; + sf2 = FLOAT_1374_40625; + sf3 = FLOAT_0_1249694824218; + sf2 = av_add_sf(sf1, sf2); + sf3 = av_add_sf(sf3, sf2); + printf("test3 softfloat: %.10lf (0x%08x %d)\n", (double)av_sf2double(sf3), sf3.mant, sf3.exp); + return 0; + } |