function testfn(f)
	print(0, 0, f(0, 0))
	print(-0, 0, f(-0, 0))
	print(0, -0, f(0, -0))
	print(-0, -0, f(-0, -0))
	print(1.23, 0, f(1.23, 0))
	print(0, 1.23, f(0, 1.23))
	print(2.34, 1.23, f(2.34, 1.23))
	print(-1.23, 2.34, f(-1.23, 2.34))
	print(0/0.0, 0, f(0/0.0, 0))
	print(0, 0/0.0, f(0, 0/0.0))
	print(0/0.0, 0/0.0, f(0/0.0, 0/0.0))
	print(0, 1/0.0, f(0, 1/0.0))
	print(0, -1/0.0, f(0, -1/0.0))
	print(1/0.0, 0, f(1/0.0, 0))
	print(1/0.0, 0/0.0, f(1/0.0, 0/0.0))
	print("0xAB", 12, f("0xAB", 12))
	print(34, "0xAB", f(34, "0xAB"))
	print("  0xFE ", "  5.43    ", f("  0xFE ", "  5.43    "))
	print(1, 2, 3, f(1, 2, 3))
	print((pcall(function() f() end)))
	print((pcall(function() f(1) end)))
	print((pcall(function() f("a", 2.3) end)))
	print((pcall(function() f(2.3, "b") end)))
end

print('-- atan2 --')
testfn(math.atan2)

print('-- pow --')
testfn(math.pow)

print('-- fmod --')
testfn(math.fmod)

function testldexp(f)
	for k = -3, 3 do
		print(0, k, f(0, k))
		print(-0, k, f(-0, k))
		print(1.23, k, f(1.23, k))
		print(-1.23, k, f(-1.23, k))
		print(0/0.0, k, f(0/0.0, k))
		print(1/0.0, k, f(1/0.0, k))
		print(-1/0.0, k, f(-1/0.0, k))
		print(1e200, k, f(1e200, k))
	end
	print(1.23, 1000, f(1.23, 1000))
	print(1.23, 3000, f(1.23, 3000))
	print(1.23, -1000, f(1.23, -1000))
	print(1.23, -3000, f(1.23, -3000))
	print(-1.23, 1000, f(-1.23, 1000))
	print(-1.23, 3000, f(-1.23, 3000))
	print(-1.23, -1000, f(-1.23, -1000))
	print(-1.23, -3000, f(-1.23, -3000))
	
	print(" -1.23 ", 23, f(" -1.23 ", 23))
	print(1.23, " 0xBA ", f(1.23, " 0xBA "))
	print("233", " 0xBA ", f("233", " 0xBA "))
end

print('-- ldexp --')
testldexp(math.ldexp)

print('-- random / randomseed -- ')
print('executing randseed', math.randomseed(1.23))
print('executing rand', math.random())
print('executing rand', math.random())
print('executing rand', math.random(10))
print('executing rand', math.random(10))
print('executing rand', math.random(10, 20))
print('executing rand', math.random(10, 20))
print('executing rand', math.random(-20, -10))
print('executing rand', math.random(-20, -10))
print('executing rand', math.random())
print('executing rand', math.random())
print('executing rand', math.random(10, 10))
print('executing rand', math.random(" 8 ", 9))
print('executing rand', math.random(10, "11"))
print('executing rand', math.random("12", " 13 "))
print('executing rand', math.random(" 0xaa "))

print('executing randseed', math.randomseed(345))
print('executing rand', math.random())
print('executing rand', math.random())
print('executing rand', math.random(10))
print('executing rand', math.random(10))
print('executing rand', math.random(10, 20))
print('executing rand', math.random(10, 20))
print('executing rand', math.random(-20, -10))
print('executing rand', math.random(-20, -10))
print('executing rand', math.random())
print('executing rand', math.random())
print('executing rand', math.random(10, 10))
print('executing rand', math.random(" 8 ", 9))
print('executing rand', math.random(10, "11"))
print('executing rand', math.random("12", " 13 "))
print('executing rand', math.random(" 0xaa "))

print('executing randseed', math.randomseed(1.23))
print('executing rand', math.random())
print('executing rand', math.random())
print('executing rand', math.random(10))
print('executing rand', math.random(10))
print('executing rand', math.random(10, 20))
print('executing rand', math.random(10, 20))
print('executing rand', math.random(-20, -10))
print('executing rand', math.random(-20, -10))
print('executing rand', math.random())
print('executing rand', math.random())
print('executing rand', math.random(10, 10))
print('executing rand', math.random(" 8 ", 9))
print('executing rand', math.random(10, "11"))
print('executing rand', math.random("12", " 13 "))
print('executing rand', math.random(" 0xaa "))

print('executing randseed', math.randomseed(345))
print('executing rand', math.random())
print('executing rand', math.random())
print('executing rand', math.random(10))
print('executing rand', math.random(10))
print('executing rand', math.random(10, 20))
print('executing rand', math.random(10, 20))
print('executing rand', math.random(-20, -10))
print('executing rand', math.random(-20, -10))
print('executing rand', math.random())
print('executing rand', math.random())
print('executing rand', math.random(10, 10))
print('executing rand', math.random(" 8 ", 9))
print('executing rand', math.random(10, "11"))
print('executing rand', math.random("12", " 13 "))
print('executing rand', math.random(" 0xaa "))

print('testing range')
for i = 1, 100 do
	v = math.random(2)
	assert(v == 1 or v == 2)
end

for i = 1, 100 do
	v = math.random(3, 4)
	assert(v == 3 or v == 4)
end
print('testing range ok')

print('testing error cases')
print((pcall(function() random(1,2,3) end)))
print((pcall(function() random(1,2,3,4) end)))
print((pcall(function() random(0) end)))
print((pcall(function() random(0.5) end)))
print((pcall(function() random(-1) end)))
print((pcall(function() random(1,0.9) end)))
print((pcall(function() random("x") end)))
print((pcall(function() random(1, "y") end)))
print('done')

