Sign in to follow this  
Followers 0
BALA

Check if a square root is a whole number

7 posts in this topic

#1 ·  Posted (edited)

How can I check if the number produced after finding the square root of a number is a whole number?

Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites



If IsInt()?

$a = '3'
$b = '3.2'

If IsInt(Number($a)) Then MsgBox(0, 1, $a)
If IsInt(Number($B)) Then MsgBox(0, 2, $B)
Back to the help file for you...

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

IsInt() works in AutoIt becasue it does not use typed variables, but rather variants that use heuristics (hints from the data itself) to determine data-type.

In other languages (and if AutoIt too if you want to) you would use the Mod function e.g.

If Mod($number, 1) = 0 Then 
    ; it's a whole number
Else
    ; not a whole number
EndIf

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

If IsInt()?

$a = '3'
$b = '3.2'

If IsInt(Number($a)) Then MsgBox(0, 1, $a)
If IsInt(Number($B)) Then MsgBox(0, 2, $B)
Back to the help file for you...
I didn't think of searching for "integer" since integers contain the set of negative numbers, but i guess in AutoIt they're interchangeable with Whole numbers. Well thanks then.

EDIT: strike that about them being interchangeable, it returns 1 for negatives.

Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

IsInt() works in AutoIt becasue it does not use typed variables, but rather variants that use heuristics (hints from the data itself) to determine data-type.

In other languages (and if AutoIt too if you want to) you would use the Mod function e.g.

If Mod($number, 1) = 0 Then 
    ; it's a whole number
Else
    ; not a whole number
EndIf

Dale

Sorry, I'm not familiar with modulus operation, what exactly is Mod() doing?

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

IsInt() works in AutoIt becasue it does not use typed variables, but rather variants that use heuristics (hints from the data itself) to determine data-type.

In other languages (and if AutoIt too if you want to) you would use the Mod function e.g.

If Mod($number, 1) = 0 Then 
    ; it's a whole number
Else
    ; not a whole number
EndIf

Dale

I do that every time someone asks this question, and you are always right there to show the "proper" way. The funny thing is, in my own code (a tad more thought put into it obviously, I use MOD myself).

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Ha! Not really trying to one-up you -- I had just started writing a reply when I noticed you had already chimed in.

@bala - many sources... see Wikipedia - Modulo Operation

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0