Author |
Message |
Diablo117
![](http://compsci.ca/v3/uploads/user_avatars/6345067144872e0c7b2cf1.jpg)
|
Posted: Tue Jul 07, 2009 8:13 pm Post subject: Checking if the result is a natural number |
|
|
What is it you are trying to achieve?
After dividing a number, I want to see if it really IS divisible by finding out if the number outputted was natural, or decimal
What is the problem you are having?
Don't know if turing can do that or not
Please specify what version of Turing you are using
4.0.5 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
syntax_error
![](http://compsci.ca/v3/uploads/user_avatars/196798963948cf16794b6e5.jpg)
|
Posted: Tue Jul 07, 2009 8:32 pm Post subject: RE:Checking if the result is a natural number |
|
|
look up, the term mod.
That should be more then enough for you.
And, yes it can. |
|
|
|
|
![](images/spacer.gif) |
Diablo117
![](http://compsci.ca/v3/uploads/user_avatars/6345067144872e0c7b2cf1.jpg)
|
Posted: Wed Jul 08, 2009 1:45 am Post subject: Re: Checking if the result is a natural number |
|
|
wow, I feel as if I've been hit over the hit with an unusually large club for me not even thinkin of using mod in that way...lol |
|
|
|
|
![](images/spacer.gif) |
saltpro15
![](http://compsci.ca/v3/uploads/user_avatars/9776171634ced6278d14c2.png)
|
Posted: Wed Jul 08, 2009 9:48 am Post subject: RE:Checking if the result is a natural number |
|
|
Turing: |
if num mod 2 = 0
then
...
end if
|
|
|
|
|
|
![](images/spacer.gif) |
apomb
![](http://compsci.ca/v3/uploads/user_avatars/6489609347028a0f2422f.png)
|
Posted: Wed Jul 08, 2009 12:17 pm Post subject: Re: RE:Checking if the result is a natural number |
|
|
saltpro15 @ Wed Jul 08, 2009 9:48 am wrote: Turing: |
if num mod 2 = 0
then
...
end if
|
wouldnt that just check if the number is even? |
|
|
|
|
![](images/spacer.gif) |
DtY
![](http://compsci.ca/v3/uploads/user_avatars/8576159234be48b7a8b0e8.png)
|
Posted: Wed Jul 08, 2009 12:51 pm Post subject: Re: RE:Checking if the result is a natural number |
|
|
apomb @ Wed Jul 08, 2009 12:17 pm wrote: saltpro15 @ Wed Jul 08, 2009 9:48 am wrote: Turing: |
if num mod 2 = 0
then
...
end if
|
wouldnt that just check if the number is even?
num mod 2 would test if it's divisible by two. You'd replace two with whatever number you need to check if you can divide by. |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Wed Jul 08, 2009 1:41 pm Post subject: RE:Checking if the result is a natural number |
|
|
Another way,,
code: |
if num div X = num/X then
...
end if
|
|
|
|
|
|
![](images/spacer.gif) |
DtY
![](http://compsci.ca/v3/uploads/user_avatars/8576159234be48b7a8b0e8.png)
|
Posted: Wed Jul 08, 2009 9:06 pm Post subject: Re: RE:Checking if the result is a natural number |
|
|
insectoid @ Wed Jul 08, 2009 1:41 pm wrote: Another way,,
code: |
if num div X = num/X then
...
end if
|
Although that method is slower and makes less sense.. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
saltpro15
![](http://compsci.ca/v3/uploads/user_avatars/9776171634ced6278d14c2.png)
|
Posted: Wed Jul 08, 2009 9:39 pm Post subject: RE:Checking if the result is a natural number |
|
|
thanks for correcting that guys |
|
|
|
|
![](images/spacer.gif) |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
Posted: Wed Jul 08, 2009 11:03 pm Post subject: Re: Checking if the result is a natural number |
|
|
I like my method.
Turing: | if num = floor(num ) then
put "Integer"
else
put "Real Number"
end if |
|
|
|
|
|
![](images/spacer.gif) |
syntax_error
![](http://compsci.ca/v3/uploads/user_avatars/196798963948cf16794b6e5.jpg)
|
Posted: Wed Jul 08, 2009 11:35 pm Post subject: Re: Checking if the result is a natural number |
|
|
Zren @ Wed Jul 08, 2009 11:03 pm wrote: I like my method.
Turing: | if num = floor(num ) then
put "Integer"
else
put "Real Number"
end if |
Hmm, seems like the smallest amount of code to me, nice. |
|
|
|
|
![](images/spacer.gif) |
|