Module:Math:修订间差异
删除的内容 添加的内容
enwiki>Ahecht Rewrite rounding and precision code to run faster, other code cleanup including removing unused variables. Please revert if this causes any unexpected side effects |
IdleTap-bot(留言 | 贡献) 导入自求闻百科 |
||
第140行:
local input_string = (args[1] or args.x or '0');
local trap_fraction = args.check_fraction;
local input_number;
if not yesno then
第157行 ⟶ 第158行:
end
if
return err('precision input appears non-numeric')
else
return p._precision(
end
end
第169行 ⟶ 第170行:
x = tostring(x)
end
x = string.upper(x)
local exponent_pos = x:find('E')
local result = 0;
if exponent_pos ~= nil then
local exponent = string.sub(x, exponent_pos + 1)
x = string.sub(x, 1, exponent_pos - 1)
if coefficient then▼
result = result -
end
▲ local i, j = x:find('%..*$')
if i then▼
▲ result = result + (j - i)
return result
end
local pos = string.len(x);
pos = pos - 1
result = result -
return 0
end
第292行 ⟶ 第296行:
function p._sum(...)
local sums, count = fold((function(a, b) return a + b end), ...)
if not sums then
return 0
第420行 ⟶ 第424行:
return oldr
end
local result, count = fold(findGcd, ...)
return result
end
第453行 ⟶ 第457行:
end
local current_precision = p._precision(value)
local order = p._order(value)
第468行 ⟶ 第471行:
if precision < current_precision then
value = p._round(value, precision)
current_precision = p._precision(value)
end
local formatted_num = lang:formatNum(
local sign
-- Use proper unary minus sign rather than ASCII default▼
sign = '−'
else
sign = ''
end
-- Handle cases requiring scientific notation
if
value = value * math.pow(10,
current_precision = current_precision + order
precision = precision + order
formatted_num = lang:formatNum(
else
order = 0;
end
▲ -- Use proper unary minus sign rather than ASCII default
▲ formatted_num = ((value < 0) and '−' or '') .. formatted_num
-- Pad with zeros, if needed
第582行 ⟶ 第589行:
]]
function p._cleanNumber(number_string
if type(number_string) == 'number' then
-- We were passed a number, so we don't need to do any processing.
第593行 ⟶ 第600行:
-- Attempt basic conversion
local number = tonumber(number_string)
▲ end
-- If failed, attempt to evaluate input as an expression
第630行 ⟶ 第628行:
]]
local mt = { __index = function(
return function(frame)
if not getArgs then
| |||