is8591 Posted February 3, 2006 Share Posted February 3, 2006 I ran into a small problem using Int(). Simple formula $result = Int($i /100 * 100) should always return $result equal to $i but it does not. So i made a simple script to run through numbers and see when it fails - see code. Result goes into a file. Int() fails consistently but on random numbers - at least I don't see a pattern. For better reading I added a colum $i /100 *100 - I thought precision was messing up but $i /100*100 always returns $i. I hope somebody can explain it. $file = FileOpen("TestErrors.txt", 2) For $i = 1 To 999 If $i <> Int($i/100 * 100) Then $s_err = $i & @TAB & $i/100*100 & @TAB & Int($i/100 * 100) FileWriteLine($file, $s_err) EndIf Next FileClose($file) Exit Link to comment Share on other sites More sharing options...
Laine Posted February 3, 2006 Share Posted February 3, 2006 I hope somebody can explain it. $file = FileOpen("TestErrors.txt", 2) For $i = 1 To 999 If $i <> Int($i/100 * 100) Then $s_err = $i & @TAB & $i/100*100 & @TAB & Int($i/100 * 100) FileWriteLine($file, $s_err) EndIf Next FileClose($file) Exit I get a testerrors.txt file of ZERO bytes. Indicating no errors were generated. Link to comment Share on other sites More sharing options...
Developers Jos Posted February 3, 2006 Developers Share Posted February 3, 2006 What version ???? Try latest BETA and see if that fixes it... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
is8591 Posted February 3, 2006 Author Share Posted February 3, 2006 What version ????Try latest BETA and see if that fixes it...I am at work - only have 3.1.1 - not allowed to use betaBut I looked through bug reports before posting and did not find any reference Int().Is there a workaround in 3.1.1 because I will not be able to switch to Beta nayway? Link to comment Share on other sites More sharing options...
Laine Posted February 3, 2006 Share Posted February 3, 2006 But I looked through bug reports before posting and did not find any reference Int().Is there a workaround in 3.1.1 because I will not be able to switch to Beta nayway?I get no errors in 3.1.1 or 105 beta Link to comment Share on other sites More sharing options...
Developers Jos Posted February 3, 2006 Developers Share Posted February 3, 2006 (edited) I am at work - only have 3.1.1 - not allowed to use betaBut I looked through bug reports before posting and did not find any reference Int().Is there a workaround in 3.1.1 because I will not be able to switch to Beta nayway?Think this one is bugging you with the 3.1.10 version fixed in BETA:07th November, 2005 - v3.1.1.87 (beta)Fixed : @DesktopHeight/Width doc typo. (Thanks PartyPooper) Added : VC8 compilation support. (by Valik) Fixed : Float to Integer precision. (Thanks kalavo, fixed by Valik) I get no errors in 3.1.1 or 105 betaI get the errors listed in testerrors.txt when running with 3.1.1.0 Edited February 3, 2006 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
is8591 Posted February 3, 2006 Author Share Posted February 3, 2006 I get no errors in 3.1.1 or 105 betaMy error file attached.TestErrors.txt Link to comment Share on other sites More sharing options...
Developers Jos Posted February 3, 2006 Developers Share Posted February 3, 2006 think this fixes it for 3.1.1.0 :$file = FileOpen("TestErrors.txt", 2)For $i = 1 To 999 If $i <> Int($i/100 * 100 + .0000000000001) Then $s_err = $i & @TAB & $i/100*100 & @TAB & Int($i/100 * 100) FileWriteLine($file, $s_err) EndIfNextFileClose($file)Exit SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Laine Posted February 3, 2006 Share Posted February 3, 2006 My error file attached.My Bad.I wasn't correctly toggling between 1.1 and 1.1.105.I get the errors now. Link to comment Share on other sites More sharing options...
Valik Posted February 3, 2006 Share Posted February 3, 2006 think this fixes it for 3.1.1.0 : $file = FileOpen("TestErrors.txt", 2) For $i = 1 To 999 If $i <> Int($i/100 * 100 + .0000000000001) Then $s_err = $i & @TAB & $i/100*100 & @TAB & Int($i/100 * 100) FileWriteLine($file, $s_err) EndIf Next FileClose($file) ExitThis will only fix it under the following conditions:The numbers are positive. If you need to adapt the solution to work with negative numbers, you will need to subtract the magic number JdeB provided.There are very few consecutive floating point operations being performed on a number before it is "corrected". If you attempt to chain together several operations involving floating point numbers, the deviation from the "true" value may exceed the hard-coded threshold JdeB is providing. Link to comment Share on other sites More sharing options...
is8591 Posted February 3, 2006 Author Share Posted February 3, 2006 This will only fix it under the following conditions:The numbers are positive. If you need to adapt the solution to work with negative numbers, you will need to subtract the magic number JdeB provided.There are very few consecutive floating point operations being performed on a number before it is "corrected". If you attempt to chain together several operations involving floating point numbers, the deviation from the "true" value may exceed the hard-coded threshold JdeB is providing.Thanks guys.it seems to eliminate the error for writing into the file but actual calculation error is still in result.I put this small script just to check if I had a problem.In actual script value is read from input field that users fill in and function needs to convert the value from dollars.cents into cents for next step calculation - so conversion is $value = Int($value*100).So how do I correct the actual error in calculations?If it something cumbersome - don't bother wit it.I used Int($value*100) to avoid checking number of digits after decimal point and stripping decimal point.I will just add theses steps in. Link to comment Share on other sites More sharing options...
Developers Jos Posted February 3, 2006 Developers Share Posted February 3, 2006 Thanks guys.it seems to eliminate the error for writing into the file but actual calculation error is still in result.I put this small script just to check if I had a problem.In actual script value is read from input field that users fill in and function needs to convert the value from dollars.cents into cents for next step calculation - so conversion is $value = Int($value*100).So how do I correct the actual error in calculations?If it something cumbersome - don't bother wit it.I used Int($value*100) to avoid checking number of digits after decimal point and stripping decimal point.I will just add theses steps in.Just add .0000000000001 within any INT() function to correct the calculation... (As long as the values are positive like Valik stated)...Did you try that ? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
is8591 Posted February 3, 2006 Author Share Posted February 3, 2006 Just add .0000000000001 within any INT() function to correct the calculation... (As long as the values are positive like Valik stated)...Did you try that ?You right - it solves the problem. Thank you very much. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now