Commit 0e1a56d1065e8cf2f2d46e7dfaa6be03a9ec2f56

Authored by DarkGod
1 parent 7dca9b2d

fixfloat

... ... @@ -914,7 +914,7 @@ function _M:addTemporaryValue(prop, v, noupdate)
914 914 -- print("Entity:", self) -- table.print(self)
915 915 -- game.debug._debug_entity = self
916 916 -- end
917   - base[prop] = (base[prop] or 0) + v
  917 + base[prop] = (base[prop] or 0) + math.fixfloat(v)
918 918 end
919 919 self:onTemporaryValueChange(prop, v, base)
920 920 -- print("addTmpVal", base, prop, v, " :=: ", #t, id, method)
... ... @@ -1014,7 +1014,7 @@ function _M:removeTemporaryValue(prop, id, noupdate)
1014 1014 if not next(base["__tlast_"..prop]) then base["__tlast_"..prop] = nil end
1015 1015 else
1016 1016 if not base[prop] then util.send_error_backtrace("Error removing property "..tostring(prop).." with value "..tostring(v).." : base[prop] is nil") return end
1017   - base[prop] = base[prop] - v
  1017 + base[prop] = base[prop] - math.fixfloat(v)
1018 1018 end
1019 1019 self:onTemporaryValueChange(prop, -v, base)
1020 1020 -- print("delTmpVal", prop, v, method)
... ... @@ -1118,7 +1118,7 @@ end
1118 1118 function _M:attr(prop, v, fix)
1119 1119 if v then
1120 1120 if fix then self[prop] = v
1121   - else self[prop] = (self[prop] or 0) + v
  1121 + else self[prop] = (self[prop] or 0) + math.fixfloat(v)
1122 1122 end
1123 1123 else
1124 1124 if self[prop] and self[prop] ~= 0 then
... ...
... ... @@ -30,6 +30,20 @@ function math.decimals(v, nb)
30 30 return math.floor(v * nb) / nb
31 31 end
32 32
  33 +-- Let's be super safe, if we cant figure out the size of double, just don't use the fixer
  34 +local ffi = require "ffi"
  35 +if not ffi or not ffi.sizeof or ffi.sizeof("double") ~= 8 then
  36 + function math.fixfloat(x)
  37 + return x
  38 + end
  39 +else
  40 + -- This is horrible horrible black magic to "binary round" floats
  41 + local _fixfloat = 2^40
  42 + function math.fixfloat(x)
  43 + return x+_fixfloat-_fixfloat
  44 + end
  45 +end
  46 +
33 47 -- Rounds to nearest multiple
34 48 -- (round away from zero): math.round(4.65, 0.1)=4.7, math.round(-4.475, 0.01) = -4.48
35 49 -- num = rounding multiplier to compensate for numerical rounding (default 1000000 for 6 digits accuracy)
... ...
... ... @@ -1427,9 +1427,9 @@ end
1427 1427 --- Scale damage values
1428 1428 -- This currently beefs up high-end damage values to make up for the combat stat rescale nerf.
1429 1429 function _M:rescaleDamage(dam)
1430   - if dam <= 0 then return math.decimals(dam, 2) end
  1430 + if dam <= 0 then return dam end
1431 1431 -- return dam * (1 - math.log10(dam * 2) / 7) --this is the old version, pre-combat-stat-rescale
1432   - return math.decimals(dam ^ 1.04, 2)
  1432 + return dam ^ 1.04
1433 1433 end
1434 1434
1435 1435 --Diminishing-returns method of scaling combat stats, observing this rule: the first twenty ranks cost 1 point each, the second twenty cost two each, and so on. This is much, much better for players than some logarithmic mess, since they always know exactly what's going on, and there are nice breakpoints to strive for.
... ... @@ -1486,12 +1486,12 @@ function _M:combatLimit(x, limit, y_low, x_low, y_high, x_high)
1486 1486 -- local add = (limit*(x_high*y_low-x_low*y_high) + y_high*y_low*(x_low-x_high))/(p-m)
1487 1487 -- return (limit-add)*x/(x + halfpoint) + add
1488 1488 local ah = (limit*(x_high*y_low-x_low*y_high)+ y_high*y_low*(x_low-x_high))/(y_high - y_low) -- add*halfpoint product calculated at once to avoid possible divide by zero
1489   - return math.decimals((limit*x + ah)/(x + (p-m)/(y_high - y_low)), 2) --factored version of above formula
  1489 + return (limit*x + ah)/(x + (p-m)/(y_high - y_low)) --factored version of above formula
1490 1490 -- return (limit-add)*x/(x + halfpoint) + add, halfpoint, add
1491 1491 else
1492 1492 local add = 0
1493 1493 local halfpoint = limit*x_high/(y_high-add)-x_high
1494   - return math.decimals((limit-add)*x/(x + halfpoint) + add, 2)
  1494 + return (limit-add)*x/(x + halfpoint) + add
1495 1495 -- return (limit-add)*x/(x + halfpoint) + add, halfpoint, add
1496 1496 end
1497 1497 end
... ... @@ -1519,10 +1519,10 @@ function _M:combatTalentScale(t, low, high, power, add, shift, raw)
1519 1519 local m = (high - low)/(x_high_adj - x_low_adj)
1520 1520 local b = low - m*x_low_adj
1521 1521 if power == "log" then -- always >= 0
1522   - return math.decimals(math.max(0, m * math.log10(tl + shift) + b + add), 2)
  1522 + return math.max(0, m * math.log10(tl + shift) + b + add)
1523 1523 -- return math.max(0, m * math.log10(tl + shift) + b + add), m, b
1524 1524 else
1525   - return math.decimals(math.max(0, m * (tl + shift)^power + b + add), 2)
  1525 + return math.max(0, m * (tl + shift)^power + b + add)
1526 1526 -- return math.max(0, m * (tl + shift)^power + b + add), m, b
1527 1527 end
1528 1528 end
... ... @@ -1548,10 +1548,10 @@ function _M:combatStatScale(stat, low, high, power, add, shift)
1548 1548 local m = (high - low)/(x_high_adj - x_low_adj)
1549 1549 local b = low -m*x_low_adj
1550 1550 if power == "log" then -- always >= 0
1551   - return math.decimals(math.max(0, m * math.log10(stat + shift) + b + add), 2)
  1551 + return math.max(0, m * math.log10(stat + shift) + b + add)
1552 1552 -- return math.max(0, m * math.log10(stat + shift) + b + add), m, b
1553 1553 else
1554   - return math.decimals(math.max(0, m * (stat + shift)^power + b + add), 2)
  1554 + return math.max(0, m * (stat + shift)^power + b + add)
1555 1555 -- return math.max(0, m * (stat + shift)^power + b + add), m, b
1556 1556 end
1557 1557 end
... ... @@ -1575,11 +1575,11 @@ function _M:combatTalentLimit(t, limit, low, high, raw)
1575 1575 -- local halfpoint = (p-m)/(high - low) -- point at which half progress towards the limit is reached
1576 1576 -- local add = (limit*(x_high*low-x_low*high) + high*low*(x_low-x_high))/(p-m)
1577 1577 local ah = (limit*(x_high*low-x_low*high)+ high*low*(x_low-x_high))/(high - low) -- add*halfpoint product calculated at once to avoid possible divide by zero
1578   - return math.decimals((limit*tl + ah)/(tl + (p-m)/(high - low)), 2) --factored version of above formula
  1578 + return (limit*tl + ah)/(tl + (p-m)/(high - low)) --factored version of above formula
1579 1579 -- return (limit-add)*tl/(tl + halfpoint) + add, halfpoint, add
1580 1580 else -- assume low and x_low are both 0
1581 1581 local halfpoint = limit*x_high/high-x_high
1582   - return math.decimals(limit*tl/(tl + halfpoint), 2)
  1582 + return limit*tl/(tl + halfpoint)
1583 1583 -- return (limit-add)*tl/(tl + halfpoint) + add, halfpoint, add
1584 1584 end
1585 1585 end
... ... @@ -1601,11 +1601,11 @@ function _M:combatStatLimit(stat, limit, low, high)
1601 1601 -- local halfpoint = (p-m)/(high - low) -- point at which half progress towards the limit is reached
1602 1602 -- local add = (limit*(x_high*low-x_low*high) + high*low*(x_low-x_high))/(p-m)
1603 1603 local ah = (limit*(x_high*low-x_low*high)+ high*low*(x_low-x_high))/(high - low) -- add*halfpoint product calculated at once to avoid possible divide by zero
1604   - return math.decimals((limit*stat + ah)/(stat + (p-m)/(high - low)), 2) --factored version of above formula
  1604 + return (limit*stat + ah)/(stat + (p-m)/(high - low)) --factored version of above formula
1605 1605 -- return (limit-add)*stat/(stat + halfpoint) + add, halfpoint, add
1606 1606 else -- assume low and x_low are both 0
1607 1607 local halfpoint = limit*x_high/high-x_high
1608   - return math.decimals(limit*stat/(stat + halfpoint), 2)
  1608 + return limit*stat/(stat + halfpoint)
1609 1609 -- return (limit-add)*stat/(stat + halfpoint) + add, halfpoint, add
1610 1610 end
1611 1611 end
... ...