Computer Science Canada

Checking if the result is a natural number

Author:  Diablo117 [ 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

Author:  syntax_error [ 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.

Author:  Diablo117 [ 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

Author:  saltpro15 [ 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

Author:  apomb [ 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?

Author:  DtY [ 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.

Author:  Insectoid [ 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

Author:  DtY [ 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..

Author:  saltpro15 [ Wed Jul 08, 2009 9:39 pm ]
Post subject:  RE:Checking if the result is a natural number

Embarassed thanks for correcting that guys

Author:  Zren [ 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

Author:  syntax_error [ 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.


: