bada-studio / knights_contract

154 stars 55 forks source link

Floating point accuracy issue about defense stat #44

Closed mjshin82 closed 5 years ago

mjshin82 commented 5 years ago

Oria total damage: 2862-27 = 2835 Scarllet total damage: 3024-189 = 2835

total damage is reduced by this formula.

kv_enemy_attack = 25;
kv_defense_base = 1000;

int damage_per_min = kv_enemy_attack;
damage_per_min -= kv_enemy_attack * knight.defense / (knight.defense + kv_defense_base);

Orial damage_per_min : 25 - 25 *1060 / (1060+1000) = 12.1359223301 => 12
Scallet damage_per_min: 25 - 25 * 938 / (938+1000) = 12.8998968008 => 12

make damage_per_min to double type.

mjshin82 commented 5 years ago

image

plimerence commented 5 years ago

I also seem to the same problem,according to the contract formula,i can not calc the right result.but according to the hp,alive hp,kill count I can calc the right result ,so it is a bug?or the github contarct is different form the contract in eos mainnet .

plimerence commented 5 years ago

@mj-raindays

mjshin82 commented 5 years ago

It was fixed int -> double https://github.com/bada-studio/knights_contract/blob/master/knights/contract/knight_control.hpp#L378