Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology
Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered
You are not logged in.
I can't seem to figure out what is wrong with the line that compares two floats:
if  ((thisremote_bot.Remote_bot_float_coefficient)  > . 1.0) thenthe editor is showing this error:
(!) Line #645:
				if  ((thisremote_bot.Remote_bot_float_coefficient)  > ??. 1.0) then
syntax error
term expectedhere is the function
fun interpolate_bots(botlist, elapsted_time_since_last_frame)=
	
	if (botlist==nil) then
	( 
	else
	(
		let hd botlist-> [id thisremote_bot] in
			(
				//force last frame and set coefficient to 1.0
				
				if  ((thisremote_bot.Remote_bot_float_coefficient) >  . 1.0) then
				(
						set thisremote_bot.Remote_bot_float_coefficient = . 1.0;
						SO3ObjectSetPosition  thisremote_bot.Remote_bot_shell thisremote_bot.Remote_bot_target_position;
      				SO3ObjectSetOrientation thisremote_bot.Remote_bot_shell thisremote_bot.Remote_bot_target_rotation;
      					
						0;
				)
				else
				(
				//close if then else brace
						0;
				);
			//close let brace	
			0;
			);
	//shrink list and perform the function again
	set botlist = tl botlist;
	interpolate_bots botlist elapsted_time_since_last_frame;
	//close if then else
	0;
	);
	0;;Last edited by hebdemnobad (30-Dec-2013 15:48:50)
Offline
solved, I see you have to put the . right after the comparison operator... > . 1.0 is wrong, it should be >. 1.0
-h
Offline
ack! same problem, except here:
else if (botcoefficient ==. 0.0) thenerror log:
(!) Line #657:
				else if (botcoefficient ==??. 0.0) then
syntax error
term expectedthis statement is fine:
if  ( botcoefficient >. 1.0) thenbut this throws an error, even though as far as I can tell it still is executed in the function block braces that are the domain of the temporary variable if ( botcoefficient:
else if (botcoefficient ==. 0.0) then![]()
full function (I altered it a bit with an else if block since no interpolation should be performed if the coefficient equals 0.0)
fun interpolate_bots (botlist, elapsted_time)=
	
	if (botlist==nil) then
	(
	
	0;
	)
	else
	(
		let hd botlist-> [id thisremote_bot] in
			(
				//force last frame and set coefficient to 1.0
				let thisremote_bot.Remote_bot_float_coefficient -> botcoefficient in
				//open let brace
				(
				if  ( botcoefficient >. 1.0) then
				(
						set  thisremote_bot.Remote_bot_float_coefficient = 1.0;
						SO3ObjectSetPosition  thisremote_bot.Remote_bot_shell thisremote_bot.Remote_bot_target_position;
      				                SO3ObjectSetOrientation thisremote_bot.Remote_bot_shell thisremote_bot.Remote_bot_target_rotation;	
						0;
				)
				else if (botcoefficient ==. 0.0) then
				(
					//don't interpolate since any call to this function should interpolate only if coefficient is more than 0 since that's what is done in the cbmove function
						0;
				)
				else
				(
				//TODO:: increase botcoefficient, interpolate, and set position and orientation
				//close if then else brace
						0;
				);
				//close let brace
				0;
				);
				
			//close let brace	
			0;
			);
	//shrink list and perform the function again
	set botlist = tl botlist;
	interpolate_bots botlist elapsted_time;
	//close if then else
	0;
	);
	0;;Last edited by hebdemnobad (30-Dec-2013 17:19:20)
Offline
strange, if I change
if (botcoefficient ==. 0.0) then to
if (botcoefficient <. 0.000001) then the code compiles without errors. is this issue a bug?
Offline
the code compiles without errors. is this issue a bug?
No.
If you want really compare strictly two float numbers, use "==" but it is a very very very bad idea.
Indeed never directly compare two floatting point numbers ! In binary, a such number can be rounded, so you can never compare two float numbers with a strict equality. The result is never safe. Use something like that instead :
var EPSILON = 0.000001;;
fun floatCompare (f1, f2)=
	EPSILON >. absf (f1 -. f2);;This function returns 1 if they are "equals" (their difference is < EPISLON), else 0. You can give any precision to EPSILON (by example, you can set it to 1.0 if you want).
To compare a float number to zero, it is the same thing :
fun floatIsZero (f)=
	EPSILON >. absf f;;It returns 1 if "equal" otherwise 0.
Remark : this is right in all languages.
Offline
thx, I'll do that Iri
Offline