Guest Posted May 6, 2015 Share Posted May 6, 2015 (edited) For $a = 0 To 1 Step 0.001 ConsoleWrite($a & @CRLF) Next Output: Edited May 6, 2015 by Guest Amended title Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 6, 2015 Moderators Share Posted May 6, 2015 gil900,No - go and read about floating point arithmetic. This affects all computers and has nothing to do with AutoIt as such.Loops are intended to have limits and be stepped through using integer values so that the loop variable remains an integer - if you decide to make the loop variable a float then you must expect this sort of thing to happen.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
AdamUL Posted May 6, 2015 Share Posted May 6, 2015 If you do need a loop like that for some reason, then use the Round function to get the output values that you want.For $a = 0 To 1 Step 0.001 ConsoleWrite(Round($a, 3) & @CRLF) NextAdam Link to comment Share on other sites More sharing options...
AndyG Posted May 6, 2015 Share Posted May 6, 2015 (edited) All is fine....Today we have 16/32/64/80(FPU)/128 Bit "width" to store a floating point number into the processor registers, In the future there are perhaps 20GBit to store a floating point number, but this does not change the fact that (with your example) only incredible many zeros stand before the last "one" ...You have definetly not limited the displayed number of the decimal digits!If you only want to see 3 decimal digits, use some of the available rounding funtions (Round(), Ceiling(), Floor() ) or (better imho) StringFormat(). Edited May 6, 2015 by AndyG Link to comment Share on other sites More sharing options...
Guest Posted May 6, 2015 Share Posted May 6, 2015 (edited) Thanks for the reply.This is not critical because I've never done such use.But for the solution with Round() that was suggested here, a better solution is to do thisFor $a = 0 To 999 ConsoleWrite($a*0.001 & @CRLF) NextI guess ..It takes fewer resources to do this with the math magic than call to the Round function all the time.I'm not sure about this but I think so Edited May 6, 2015 by Guest Fixed example Link to comment Share on other sites More sharing options...
BrewManNH Posted May 6, 2015 Share Posted May 6, 2015 That won't work, try it with the numbers in your original post, If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Guest Posted May 6, 2015 Share Posted May 6, 2015 (edited) Why? This:For $a = 0 To 999 ConsoleWrite($a*0.001 & @CRLF) Next And this:For $a = 0 To 1 Step 0.001 ConsoleWrite(Round($a, 3) & @CRLF) Next Print the same output. I looked twice. Or I don't see well? Melba23and has nothing to do with AutoIt as such.Why?Why not do that the Autoit core that executes the script will reed this code for example:For $a = 0 To 1 Step 0.001 ConsoleWrite($a & @CRLF) Next And tell to the processor to do this:For $a = 0 To 999 ConsoleWrite($a*0.001 & @CRLF) Next? That's how you create a language which throws this junk processor stuff (floating point) in the loop case.. If you ask me, I prefer it like this.But I just giving suggestion Edited May 6, 2015 by Guest Link to comment Share on other sites More sharing options...
jchd Posted May 6, 2015 Share Posted May 6, 2015 For stop on equality with the upper bound. Another clean and safe way to perform such loops with floating-point start value or incrment:Local $value = 0 While $value < 1.0005 ; do something with $value $value += 0.001 WEndCan be done with a Do .. Until loop as well. For is best used with integral start, increment and end values. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Guest Posted May 6, 2015 Share Posted May 6, 2015 jchd It prints the exact same "bug". Did you check it? Or I did not understand what your intention?The only solution I've found that works is to use the integer variables * 0.001 ... Link to comment Share on other sites More sharing options...
jchd Posted May 6, 2015 Share Posted May 6, 2015 No, it stops correctly. What you persist to call a bug isn't one. You just need to realize that most (by very far) real values (elements of the field ℝ) can't be represented exactly in a double, whatever programming language you use. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Guest Posted May 6, 2015 Share Posted May 6, 2015 (edited) Attempt to write down on paper (leave your computer. Use the old way):0.071 + 0.001And tell me if you came to 0.0720000000000001And also tell me how you did it.. (Do it the way the computer do it) Edited May 6, 2015 by Guest Link to comment Share on other sites More sharing options...
JohnOne Posted May 6, 2015 Share Posted May 6, 2015 Are you aware that a computer machine works in binary? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Guest Posted May 6, 2015 Share Posted May 6, 2015 Yes.I just want to get it how from 0.071 it go to 0.0720000000000001 Link to comment Share on other sites More sharing options...
jchd Posted May 6, 2015 Share Posted May 6, 2015 So work out how these values are represented by IEEE 488 floating-point, then report what you found. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Tekk Posted May 7, 2015 Share Posted May 7, 2015 Floating Point Explained Link to comment Share on other sites More sharing options...
jpm Posted May 7, 2015 Share Posted May 7, 2015 as Tekk awesome video explains the Precision of Floating point number is 23 binary digit which corresponds.e to 15 decimal digits so the last one is the 16 decimal digit which is not significantThat the limit of floating point number (15 decimal digit) II hope gil900 can understandCheers Link to comment Share on other sites More sharing options...
TheDcoder Posted May 7, 2015 Share Posted May 7, 2015 (edited) AutoIt is made in C++ Coding in C++ = Problems with maths Edited May 7, 2015 by TheDcoder Made my post clear EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 7, 2015 Moderators Share Posted May 7, 2015 TheDcoder,Coding in C++ = Problems with mathsNo, the problem is entirely independent of language - it is the result of trying to store floating point numbers in binary format, so any computer in any language will be affected unless the app used has specialist routines to deal with it. For example, software that deals with currency often converts every value to the lowest value unit (pence, cents, etc) so that the values are integers for any calculations and then reconverts the answer to the more commonly used larger units.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
TheDcoder Posted May 7, 2015 Share Posted May 7, 2015 Thanks for the very quick lesson @Melba23 EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
guinness Posted May 7, 2015 Share Posted May 7, 2015 Coding in C++ = Problems with mathsYou've just ostracized yourself from the C++ community with that comment. Haha, well done! UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 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