View Full Version : Is there a difference in float values of Avisynth parser and vc++?
vcmohan
27th September 2006, 03:34
In a plugin I was trying I have a statement for parameter checking as below
if( args[3].AsFloat(0.02) < 0.001 || args[3].AsFloat(0.02) >0.9 )
env->ThrowError("...........");
I find if I specify for my parameter in the script as .001 or 0.9 I get error. However if I have in the if statement 0.002 or 0.5 and specify my parameter as 0.002 or 0.5 I do not get error. It looks that for certain float values what Avisynth conveys internally is different than what VC++ thinks they are.
Is this normal?
foxyshadis
27th September 2006, 04:23
Welcome to the wonderfully fun world of IEEE float roundoff errors (http://www.cs.princeton.edu/introcs/91float/), unfortunately quite common. The quickest way to avoid it is to minutely underspecify what you really want, ie, 0.000999999 (or 0.001-1e8) and 0.9000001.
Avisynth's parser is only float precision, btw, compared to the normal double precision of constants in C++.
Fizick
27th September 2006, 04:52
try this:
if( args[3].AsFloat(0.02f) < 0.001f || args[3].AsFloat(0.02f) >0.9f )
env->ThrowError("...........");
IanB
28th September 2006, 04:19
also try this:
if( !( args[3].AsFloat(0.02f) >= 0.001f) || !(args[3].AsFloat(0.02f) <= 0.9f ))
env->ThrowError("...........");
The <= and >= are no quite exactly opposite to > and < respectively.
Also the AVSValue.AsFloat() for some dumb reason goes thru a double in the calcs.
vcmohan
29th September 2006, 03:23
I tried suggestions of Fizick and IanB given above. But no luck. I get the same error. May be suggestion of Foxyshadis may be the only way though on the face of it appears unsatisfactory. The other thing to do is to give an error message stating that values can be only between 0.001 and 0.9 (excluding both).But that is lying.
IanB
29th September 2006, 06:01
You could always debug print the numbers out in hex and hand evaluate them to see what is truely happening. Look at the code in filters/fps.cpp for some hints on how to unpack fp numbers.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.