Author Topic: Massive calculation fail [solved]  (Read 1180 times)

0 Members and 1 Guest are viewing this topic.

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Massive calculation fail [solved]
« on: May 05, 2011, 01:29:24 pm »
We all(i think) know that (a-b) = -(b-a), all except soldat server, which also creates non-arithmetic sequences out of arithmetic sequence formulas...
Code: [Select]
B= 6;
A= ( 693 / (B-1) );

i: byte;
j: single;
k: single;

k:= -600;
for i:= 0 to (B - 1) do begin
  [...]
  j:= k - (i * A);
  WriteLnFile([...],IntToStr(i) + ': ' + FloatToStr(j));
 
  if ( -( (i * A) - k ) ) = (k - (i * A)) then WriteLnFile('soldat can haz maths');
 
  [...]
end;

  OUTPUT IN FILE:
0: -600
soldat can haz maths
1: -738
soldat can haz maths
2: -620
3: -758
4: -640
5: -778

I just don't know what else to say... help?
« Last Edit: May 05, 2011, 04:04:49 pm by Gizd »

Offline VirtualTT

  • Veteran
  • *****
  • Posts: 1026
Re: Massive calculation fail
« Reply #1 on: May 05, 2011, 02:07:13 pm »
Code: (pascal) [Select]
i: longint;
« Last Edit: May 08, 2011, 02:56:55 pm by VirtualTT »

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Massive calculation fail
« Reply #2 on: May 05, 2011, 04:04:34 pm »
Oh right, I forgot about variable types influencing calculation in unpredictable ways. Thanks.

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Massive calculation fail [solved]
« Reply #3 on: May 06, 2011, 11:16:22 am »
is that only my feeling or there are really part of lolcode inside of it?
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline VirtualTT

  • Veteran
  • *****
  • Posts: 1026
Massive calculation fail [still aroud]
« Reply #4 on: May 08, 2011, 02:45:31 pm »
check this out:
Code: (pascal) [Select]
procedure ActivateServer();
var
i: integer;
begin
i:= 214;
writeln(inttostr(i) + ' shl=' + inttostr(i shl 1) + ' *2=' + inttostr(i * 2) + ' shr=' + inttostr(i shr 1) + ' /2=' + inttostr(i / 2));
i:= i * -1;
writeln(inttostr(i) + ' shl=' + inttostr(i shl 1) + ' *2=' + inttostr(i * 2) + ' shr=' + inttostr(i shr 1) + ' /2=' + inttostr(i / 2));
end;
output:
Code: [Select]
214 shl=428 *2=428 shr=107 /2=107
-214 shl=-428 *2=-428 shr=2147483541 /2=-107
My guess is that it always treats value as unsigned.
« Last Edit: May 08, 2011, 02:52:24 pm by VirtualTT »