Skip to content

Commit 26aba7c

Browse files
committed
xxx
1 parent 1db12e5 commit 26aba7c

File tree

8 files changed

+48
-18
lines changed

8 files changed

+48
-18
lines changed

tests/lapi/math_acos_test.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ local function TestOneInput(buf)
2020
local y = math.acos(x)
2121
assert(y >= 0)
2222
assert(y <= math.pi)
23+
local epsilon = 1^-10
2324
if x ~= 0 then
24-
assert(test_lib.approx_equal(y, math.pi - math.acos(-x), 0.01))
25-
assert(test_lib.approx_equal(math.cos(y), x, 0.01))
25+
assert(test_lib.approx_equal(y, math.pi - math.acos(-x), epsilon))
26+
assert(test_lib.approx_equal(math.cos(y), x, epsilon))
2627
end
2728
end
2829

tests/lapi/math_asin_test.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ local function TestOneInput(buf)
1818
local fdp = luzer.FuzzedDataProvider(buf)
1919
local x = fdp:consume_number(-1, 1)
2020
local y = math.asin(x)
21+
assert(type(y) == "number")
2122
assert(y >= -math.pi / 2)
2223
assert(y <= math.pi / 2)
23-
assert(test_lib.approx_equal(math.sin(y), x, 0.01))
24+
local epsilon = 1^-10
25+
assert(test_lib.approx_equal(math.sin(y), x, epsilon))
2426
end
2527

2628
local args = {

tests/lapi/math_atan_test.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ local function TestOneInput(buf)
1818
local fdp = luzer.FuzzedDataProvider(buf)
1919
local x = fdp:consume_number(test_lib.MIN_INT, test_lib.MAX_INT)
2020
local y = math.atan(x)
21+
assert(type(y) == "number")
2122
assert(y >= -math.pi / 2)
2223
assert(y <= math.pi / 2)
2324
assert(math.atan(-x) == -y)

tests/lapi/math_cos_test.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,19 @@ local test_lib = require("lib")
1717
local function TestOneInput(buf)
1818
local fdp = luzer.FuzzedDataProvider(buf)
1919
local x = fdp:consume_number(test_lib.MIN_INT, test_lib.MAX_INT)
20-
local res = math.cos(x)
21-
assert(type(res) == "number")
20+
local cos_x = math.cos(x)
21+
assert(type(cos_x) == "number")
22+
assert(cos_x >= -1 and cos_x <= 1)
23+
local epsilon = 1^-10
24+
25+
local n = fdp:consume_number(0, 100)
26+
-- Calculate the functions of the form `cos(i*pi - x), where
27+
-- i = 1, 3, 5, etc. These functions are equivalent, given the
28+
-- trigonometric identity.
29+
for i = 1, n do
30+
assert(test_lib.approx_equal(
31+
math.abs(math.cos(i * math.pi - x)), math.abs(cos_x), epsilon))
32+
end
2233
end
2334

2435
local args = {

tests/lapi/math_log_test.lua

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,29 @@ local function TestOneInput(buf, _size)
3838
local b = fdp:consume_number(test_lib.MIN_INT, test_lib.MAX_INT)
3939
if b < 0 or b == 1 then return -1 end
4040

41+
local eps = 1^-10
42+
4143
-- Product rule.
42-
assert(test_lib.approx_equal(math.log(x * y, b),
43-
math.log(x, b) + math.log(y, b), 0.01))
44+
assert(test_lib.approx_equal(
45+
math.log(x * y, b), math.log(x, b) + math.log(y, b), eps))
4446
-- Quotient rule.
45-
-- assert(test_lib.approx_equal(math.log(x / y, b), math.log(x, b) - math.log(y, b), 0.5))
46-
47+
assert(test_lib.approx_equal(
48+
math.log(x / y, b), math.log(x, b) - math.log(y, b), eps))
4749
-- Power rule.
48-
assert(test_lib.approx_equal(math.log(pow(x, y), b), y * math.log(x, b), 0.01))
50+
assert(test_lib.approx_equal(
51+
math.log(pow(x, y), b), y * math.log(x, b), eps))
4952
-- Inverse property of logarithm.
50-
assert(test_lib.approx_equal(math.log(pow(b, x), b), x, 0.01))
53+
assert(test_lib.approx_equal(math.log(pow(b, x), b), x, eps))
5154
-- Inverse property of exponent.
52-
assert(test_lib.approx_equal(pow(b, math.log(x, b)), x, 0.01))
55+
assert(test_lib.approx_equal(pow(b, math.log(x, b)), x, eps))
5356
-- Zero rule.
5457
assert(math.log(1, b) == 0)
5558
-- Identity rule.
56-
assert(test_lib.approx_equal(math.log(b, b), 1, 0.1))
59+
assert(test_lib.approx_equal(math.log(b, b), 1, eps))
5760
-- Change of base formula.
5861
local log_b_y = math.log(b, y)
5962
if log_b_y ~= 0 then
60-
assert(test_lib.approx_equal(math.log(x, b), math.log(x, y) / log_b_y, 0.01))
63+
assert(test_lib.approx_equal(math.log(x, b), math.log(x, y) / log_b_y, eps))
6164
end
6265
end
6366

tests/lapi/math_sin_test.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,19 @@ local function TestOneInput(buf)
1919
local x = fdp:consume_number(test_lib.MIN_INT, test_lib.MAX_INT)
2020
local sin_x = math.sin(x)
2121
assert(type(sin_x) == "number")
22+
assert(sin_x >= -1 and sin_x <= 1)
2223
local cos_x = math.cos(x)
23-
assert(type(cos_x) == "number")
24-
assert(test_lib.approx_equal(cos_x^2 + sin_x^2, 1, 0.01))
24+
local epsilon = 1^-10
25+
assert(test_lib.approx_equal(cos_x^2 + sin_x^2, 1, epsilon))
26+
27+
local n = fdp:consume_number(0, 100)
28+
-- Calculate the functions of the form `sin(i*pi - x), where
29+
-- i = 1, 3, 5, etc. These functions are equivalent, given the
30+
-- trigonometric identity.
31+
for i = 1, n do
32+
assert(test_lib.approx_equal(
33+
math.abs(math.sin(i * math.pi - x)), math.abs(sin_x), epsilon))
34+
end
2535
end
2636

2737
local args = {

tests/lapi/math_sqrt_test.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ local function TestOneInput(buf)
3131
-- see [1].
3232
--
3333
-- 1. https://github.com/LuaJIT/LuaJIT/issues/684#issuecomment-822427297
34-
assert(test_lib.approx_equal(math.sqrt(x), x^0.5, 0.01))
34+
local epsilon = 1^-10
35+
assert(test_lib.approx_equal(math.sqrt(x), x^0.5, epsilon))
3536
end
3637

3738
local args = {

tests/lapi/math_tan_test.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ local function TestOneInput(buf)
2121
local cos_x = math.cos(x)
2222
local tan_x = math.tan(x)
2323

24+
local epsilon = 1^-10
2425
if cos_x ~= 0 then
25-
assert(test_lib.approx_equal(tan_x, sin_x / cos_x, 0.01))
26+
assert(test_lib.approx_equal(tan_x, sin_x / cos_x, epsilon))
2627
end
2728
end
2829

0 commit comments

Comments
 (0)