Author: David Schneider <david.schnei...@picle.org> Branch: extradoc Changeset: r4437:17df7ae6ed74 Date: 2012-08-07 09:28 +0200 http://bitbucket.org/pypy/extradoc/changeset/17df7ae6ed74/
Log: merge heads diff --git a/talk/dls2012/licm-submitted.pdf b/talk/dls2012/licm-submitted.pdf new file mode 100644 index 0000000000000000000000000000000000000000..dd7d2286dbdb2201e2f9e266c9279ce9a9ba2a0d GIT binary patch [cut] diff --git a/talk/iwtc11/benchmarks/sqrt/sqrt.lua b/talk/iwtc11/benchmarks/sqrt/sqrt.lua new file mode 100644 --- /dev/null +++ b/talk/iwtc11/benchmarks/sqrt/sqrt.lua @@ -0,0 +1,89 @@ +function sqrt(y, n) + n = n or 10000 + x = y / 2 + while n > 0 do + n = n - 1 + x = (x + y/x) / 2 + end + return x +end + +----------------------- +-- begin class Fix16 -- +----------------------- + +Fix16 = {} +Fix16.__index = Fix16 + +function Fix16.init(val, scale) + if scale == nil then + scale = true + end + + local fix16 = {} + setmetatable(fix16, Fix16) + if type(val) == "table" then + fix16.val = val.val + else + if scale == true then + fix16.val = math.floor(val * (2 ^ 16)) + else + fix16.val = val + end + end + return fix16 +end + +function Fix16:__add(other) + return Fix16.init(self.val + Fix16.init(other).val, false) +end + +function Fix16:__mul(other) + value = (self.val / 256) * (Fix16.init(other).val / 256) + return Fix16.init(value, false) +end + +function Fix16:__div(other) + value = (self.val * 256) / (Fix16.init(other).val / 256) + return Fix16.init(value, false) +end + +function Fix16:to_float() + return self.val / (2 ^ 16) +end + +function Fix16:__tostring() + return tostring(self:to_float()) +end + +--------------------- +-- end class Fix16 -- +--------------------- + +function test_sqrt() + t = {2, 3, 4, 5, 6, 7, 8, 9, 123} + for j = 1, #t do + i = t[j] + s = string.format("%d %f %4.2f %4.2f %4.2f", i, sqrt(i), sqrt(i), sqrt(Fix16.init(i)):to_float(), math.sqrt(i)) + print(s) + end +end + +-- entry point +function main(args) + arg = args[1] + if arg == "int" then + sqrt(123, 100000000) + elseif arg == "float" then + sqrt(123, 100000000) + elseif arg == "Fix16" then + sqrt(Fix16.init(123), 100000000) + elseif arg == "test_sqrt" then + test_sqrt() + else + error('argument must be "int", "float" or "Fix16"') + end + return string.format("%s", arg) +end + +--main(arg) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit