PDA

View Full Version : Something wrong with my calculations?



Fardreamer
02-05-2001, 12:40 PM
Here's a short summary of what I'm trying to do: I'm trying to defragment this integer - 210110131 into four integers: 2, 1011, 013, and 1. Here are my calculations:

For the first int I just run a 'bigger than or equals' check because the long integer is always smaller than 3*10^8 (the first digit is always 1 or 2).

For the three other ints, A, B and C, I run the following:

a = (longint - 200000000)/10000;
b = ((longint - 200000000) - (a*10000))/10;
c = ((longint - 200000000) - (a*10000)) - (b*10);

The problem is that the cog retrieves only A (it prints to screen 1011) but leaves B and C assigned with zero, instead of B = 13 and C = 1.

Is something wrong with the way I handle the integers?

[This message has been edited by Fardreamer (edited February 05, 2001).]

Hideki
02-06-2001, 05:18 AM
How about you do this from the lower integer.



d = longint % 10;
c = (longint - longint % 10) / 10 % 1000;
b = (longint - longint % 10000) / 10000 % 10000;
a = (longint - longint % 100000000) / 100000000;


I think it does "%" then "-". If not, put brackets.

------------------
http://millennium.massassi.net/ - Millennium

Fardreamer
02-07-2001, 05:59 AM
I tried that. For some bizarre reason, 210110131 % 10 gave me 8!!! (instead of 1). I wonder if % is really modulus and doesn't have a different function in cog.

Hideki
02-07-2001, 07:50 AM
The value of that integer might be going over the limit of an integer that JK can handle.

In short, maybe the number is too big.

Try to print it out and see if it prints as is.

------------------
http://millennium.massassi.net/ - Millennium

[This message has been edited by Hideki (edited February 07, 2001).]

Fardreamer
02-07-2001, 09:38 AM
Oh, no; it prints just fine, since the JK integer's range is "-2,147,483,648 to +2,147,483,648 signed 32 bit whole number".

Hideki
02-07-2001, 04:17 PM
Let me see the cog.

or try "flex, thing, etc" http://forums.massassi.net/html/wink.gif might work.

------------------
http://millennium.massassi.net/ - Millennium