### C Zeng (view profile)

on 14 Mar 2013
Latest activity Edited by per isakson

on 16 Jan 2015

### per isakson (view profile)

Hi, by the command of isinteger I can check if it is an integer, however, when defined at first, Matlab assume it is double precision right? So even a=3, isinteger(a) returns 0.

How to solve this problem?

## Products

No products are associated with this question.

### per isakson (view profile)

on 14 Mar 2013
Edited by per isakson

### per isakson (view profile)

on 16 Jan 2015

Matlab represents integers in differnt ways:

• int8, int16, etc. see Christians answer
• with a special use of double, which is called flint. See Floating Points

I use this function to test for flint

```    function    isf = isflint( m )
%   floating double only
try
bitand( abs( m ), 1 );
isf = true;
catch me
isf = false;
end
end```

I picked up the idea from a contribution by the "Pedestrian" in the FEX.

(I stripped off comments and error handling.)

C Zeng

### C Zeng (view profile)

on 15 Mar 2013

Thanks, Isakson, will take a look.

Jan Simon

### Jan Simon (view profile)

on 16 Mar 2013

The problem is to decide, if 1e17 is an integer or not: Because a double can store 16 digits only, this number does not contain any information about the fractional part for reasons of the precision. bitand() detect this and throw an error, while 1e17==round(1e17) replies true, because cropping the fractional part does not influence value.

C Zeng

### C Zeng (view profile)

on 17 Mar 2013

Thanks, I understand it. It is good to know.

### Jan Simon (view profile)

on 16 Mar 2013

Joining the rounding with the checks for overflows:

```function isf = isflint(m)
isf = (abs(m) <= bitmax && m == floor(m));
```

per isakson

### per isakson (view profile)

on 18 Mar 2013

I'll replace my cryptic isflint.

### ChristianW (view profile)

on 14 Mar 2013
```doc isinteger
```
```isinteger(int8(3))
```

C Zeng

### C Zeng (view profile)

on 16 Mar 2013

yes, I used x==round(x) or floor(x). what do you mean by "isint = @(x)"?

Jan Simon

### Jan Simon (view profile)

on 16 Mar 2013

@C Zeng: @(x) x==round(x) is an anonymous function. You find an exhaustive description ion the documentation.

C Zeng

### C Zeng (view profile)

on 17 Mar 2013

OK

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi