[FFmpeg-devel] [PATCH] libavutil/softfloat: Add test case for av_add_sf

Nedeljko Babic nedeljko.babic at imgtec.com
Thu May 14 15:36:36 CEST 2015


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 at imgtec.com>
---
 libavutil/softfloat.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/libavutil/softfloat.c b/libavutil/softfloat.c
index bf9cfda..b6e1f35 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;
+
 }
-- 
1.8.2.1



More information about the ffmpeg-devel mailing list