mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-24 13:56:33 +02:00
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>
This commit is contained in:
parent
019daa0775
commit
729466dc68
@ -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;
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user