921kiyo
921kiyo

Reputation: 572

Why is the type of integer "3" a float in MATLAB?

I am new to MATLAB and am confused with types. Why is 3 the float and not integer??

>> isa(3, 'float')
ans =

logical

1

>> isa(3, 'integer')

ans =

logical

0

Upvotes: 1

Views: 63

Answers (1)

Richard
Richard

Reputation: 1060

In the MATLAB documentation on Numeric Types, you can read that

By default, MATLAB stores all numeric values as double-precision floating point.

Therefore, isa(3, 'float') (or isfloat(3) ) returns true.

You can store a number explicitly as an integer:

isinteger(uint8(3))
ans =

  logical

   1

This example from the MATLAB documentation should also be very helpful.

You can use any of the integer types in MATLAB, which are

int8    
int16   
int32   
int64   
uint8   
uint16  
uint32  
uint64

Upvotes: 3

Related Questions