From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to find whether a given number is integer?

Solved!
Go to solution

hello,

 

How can i find out whether a given number ( a variable after simplification holds a value) is an integer or not.?

 

I thought i could use isinteger( ) function in mathscript, but it does not exist- is giving error

 

can i do it without mathscript?

 

 

Thanks,

0 Kudos
Message 1 of 11
(16,756 Views)

In LabVIEW, an integer has a blue wire and terminals.

 

You probably want to know if a floating point number (orange wire) is an integer or not.

 

This can be very tricky, because if the value is the result of some computations, it could be off by a few bits. You probably want to test instead if the value is "sufficiently close" to an integer.

 

If you don't care about possible complications (however you really should!!!), you could use quotient&remainder to divide by 1 and see if the remainder is zero. You could also compare the original value with the same value fed across "round to nearest" and see if they are equal.

 

Can you explain in a bit more details what you are actually trying to do, e.g. with an example?

 

Message 2 of 11
(16,751 Views)
How about the Type String output of Flatten To String with Convert 7.x Data checked?  Help says it "is an encoded binary description of data string"...
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 3 of 11
(16,745 Views)

well, the equation i am trying to solve is f = ( m/N)*fs,

where fs - sampling frequency , f is the analog frequency and N - no of points.

 

m should be a integer for  correct sampling. so i have to check whether for a given fs, as i vary f, m is an integer or not,

 

if not, i have to round it the nearest integer.

 

so, basically there are two requirements -  find out if it is an integer, if not, round it of..

 

Many thanks.

0 Kudos
Message 4 of 11
(16,744 Views)

Can't you just make "m" an integer data type?

 

-D

0 Kudos
Message 5 of 11
(16,740 Views)

I assume you want m/N to be a (possibly rounded up) integer. Is this correct.

 

In this case, you could do something like the following?

 

Message Edited by altenbach on 01-25-2009 04:47 PM
Message 6 of 11
(16,721 Views)
Sounds to me like you should always call Round to Nearest. If it's already an integer, this is harmless (if slightly inefficient). If it's not an integer, it will be.
Jarrod S.
National Instruments
0 Kudos
Message 7 of 11
(16,712 Views)

altenbach,

 

as you had said earlier, i tried dividing  the number by 1 ( making 1 as an integer  - i.e blue wire )- then find if remainder is 0 or not.

 

to round it  - i used conversion to U32 or U16.

 

This seems to be working.

 

But should it not have  type casted the int ( blue wire ) to  float (orange)  before dividing.? 

 

Thanks..
0 Kudos
Message 8 of 11
(16,616 Views)
Rebelstar: Are you familiar with coersion dots? Labview will always convert numerical values to what it needs at the input to any function. If you wire a U8 and the input expects a U32, you will see a small red dot at the input to the function. So you don't really have to convert, but you must be sure you won't be affecting the data quality. If you convert a U32 to a U8, you will lose the upper bytes. All divisions will produce a floating point output, even if the inputs are two integers. In fact, the inputs to a divide function will have red coersion dots at the input terminals if the number is not a floating point. You do not have to convert to float, Labview does it for you. As far as whether to test whether a number is an integer or not, just convert to integer anyway. It won't corrupt the data to convert a U32 into a U32. So save the time and code and just do the conversion regardless of the input.
- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 11
(16,601 Views)
Solution
Accepted by topic author rebelstar

rebelstar wrote:

But should it not have  type casted the int ( blue wire ) to  float (orange)  before dividing.? 


Quoteient&rmainder works natively on integers as well as floating point. No need to convert. Simply make sure that the two inputs match. For example don't use an orange "1" if the upper input is blue. Make the diagram constant the same representation as the other input. Look at the picture I attached earlier. No coercion dots.

0 Kudos
Message 10 of 11
(16,595 Views)