Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Can any body help me on this matlab program

Status
Not open for further replies.

bavamurali

Member level 1
Member level 1
Joined
Aug 4, 2007
Messages
41
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
india
Activity points
1,475
my matlab program is like this

i=90030021002145212;
b=90030021003000000;
while(i<b)
fprintf('%f\n',i);
i=i+1;
end

try this one and solve it i want increment of one
 

Your initial value is too large and increment of one in this case is impossible.

By default, matlab use double precision floating point, and there is limitation of floating point representation.
Floating-point are saved in exponential way, so it can represent very small value (precise number) at one time, and represent very large value (large range) at another time, but both large range and precise number can't be obtained at the same time.
When you add a very large value with a very small one, the small number will be neglected.

If you want increment of one, try smaller initial value.
 
thanks for your reply but in the program i should use large value is there any method of incrementing large value by one
 

Subtract the two numbers and run the difference:
Code:
k=b-i; 
k=0;
while(n<k)
  fprintf('%f\n',i+k);
  k=k+1;
end
...or something like this...
 

matlab has some key format you can use.
in matlab command windows type >>format long
in this mode you can use larger number.
read format help file for more details.
 

Does this work. It does not on my old matlab but in up to date versions I think 64 bit integers are supported.

i=uint64(90030021002145212);
b=uint64(90030021003000000);
while(i<b)
fprintf('%u\n',i);
i=i+1;
end
 

If you want to go that route, you need to define your own operators since
No math operations are defined for the UINT64.
from help uint64.
 

Yes, I agree with you guys. It can be solved by using 64 bits integer, but you must define + operator by yourself because matlab doesn't support math for uint64.

But I found another problem. I tried this in matlab command window and found inaccurate values:
Code:
i=uint64(90030021002145212)

i =

    90030021002145216

When we declare uint64(something), matlab save the original number in double which has bad precision in large value, then cast it to integer format.

I guess writing those code in C language will be easier.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top