Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix positive? and negative? on NaN floating number #160

Merged
merged 13 commits into from
Nov 11, 2024
40 changes: 34 additions & 6 deletions Goldfish.tmu
Original file line number Diff line number Diff line change
Expand Up @@ -1285,9 +1285,9 @@
\;
</scm-chunk>

<value|r7rs><paragraph|positive?><index|positive?><scm|(x) =\<gtr\> boolean?>
<value|r7rs><paragraph|positive?><index|positive?><scm|((x real?)) =\<gtr\> boolean?>

判断一个数是否为正数
判断一个实数是否为正数

<subparagraph|真>

Expand All @@ -1298,6 +1298,10 @@

(check-true (positive? 1/2))

(check-true (positive? +inf.0))

(check-true (positive? 1+0i))

\;
</scm-chunk>

Expand All @@ -1312,24 +1316,34 @@

(check-false (positive? -1/2))

(check-false (positive? -inf.0))

(check-false (positive? +nan.0))

\;
</scm-chunk>

<subparagraph|类型错误>

<\scm-chunk|tests/goldfish/liii/base-test.scm|true|true>
(check-catch 'wrong-type-arg (positive? 1+1i))

(check-catch 'wrong-type-arg (positive? #\\A))

(check-catch 'wrong-type-arg (positive? #t))

(check-catch 'wrong-type-arg (positive? #f))
(check-catch 'wrong-type-arg (positive? "not-a-number"))

(check-catch 'wrong-type-arg (positive? 'symbol))

(check-catch 'wrong-type-arg (positive? '(1 2 3)))

\;
</scm-chunk>

<value|r7rs><paragraph|negative?><index|negative?><scm|(x) =\<gtr\> boolean?>
<value|r7rs><paragraph|negative?><index|negative?><scm|((x real?)) =\<gtr\> boolean?>

判断一个数是否为负数
判断一个实数是否为负数

<subparagraph|真>

Expand All @@ -1340,6 +1354,10 @@

(check-true (negative? -1/2))

(check-true (negative? -inf.0))

(check-true (negative? -1+0i))

\;
</scm-chunk>

Expand All @@ -1354,17 +1372,27 @@

(check-false (negative? 1/2))

(check-false (negative? +inf.0))

(check-false (negative? -nan.0))

\;
</scm-chunk>

<subparagraph|类型错误>

<\scm-chunk|tests/goldfish/liii/base-test.scm|true|true>
(check-catch 'wrong-type-arg (negative? -1-1i))

(check-catch 'wrong-type-arg (negative? #\\A))

(check-catch 'wrong-type-arg (negative? #t))

(check-catch 'wrong-type-arg (negative? #f))
(check-catch 'wrong-type-arg (negative? "not-a-number"))

(check-catch 'wrong-type-arg (negative? 'symbol))

(check-catch 'wrong-type-arg (negative? '(1 2 3)))

\;
</scm-chunk>
Expand Down
1 change: 1 addition & 0 deletions src/goldfish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ int
main (int argc, char** argv) {
return goldfish::repl_for_community_edition (argc, argv);
}

18 changes: 16 additions & 2 deletions tests/goldfish/liii/base-test.scm
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,42 @@
(check-true (positive? 1))
(check-true (positive? 0.1))
(check-true (positive? 1/2))
(check-true (positive? +inf.0))
(check-true (positive? 1+0i))

(check-false (positive? 0))
(check-false (positive? -1))
(check-false (positive? -1.1))
(check-false (positive? -1/2))
(check-false (positive? -inf.0))
(check-false (positive? +nan.0))

(check-catch 'wrong-type-arg (positive? 1+1i))
(check-catch 'wrong-type-arg (positive? #\A))
(check-catch 'wrong-type-arg (positive? #t))
(check-catch 'wrong-type-arg (positive? #f))
(check-catch 'wrong-type-arg (positive? "not-a-number"))
(check-catch 'wrong-type-arg (positive? 'symbol))
(check-catch 'wrong-type-arg (positive? '(1 2 3)))

(check-true (negative? -1))
(check-true (negative? -0.1))
(check-true (negative? -1/2))
(check-true (negative? -inf.0))
(check-true (negative? -1+0i))

(check-false (negative? 0))
(check-false (negative? 1))
(check-false (negative? 1.1))
(check-false (negative? 1/2))
(check-false (negative? +inf.0))
(check-false (negative? -nan.0))

(check-catch 'wrong-type-arg (negative? -1-1i))
(check-catch 'wrong-type-arg (negative? #\A))
(check-catch 'wrong-type-arg (negative? #t))
(check-catch 'wrong-type-arg (negative? #f))
(check-catch 'wrong-type-arg (negative? "not-a-number"))
(check-catch 'wrong-type-arg (negative? 'symbol))
(check-catch 'wrong-type-arg (negative? '(1 2 3)))

(check (floor 1.1) => 1.0)
(check (floor 1) => 1)
Expand Down
2 changes: 2 additions & 0 deletions xmake/packages/s/s7/port/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ target("libs7") do
add_includedirs(".", {public = true})
add_options("gmp")
if is_plat("windows") then
set_optimize("faster")
set_languages("c11")
add_cxxflags("/fp:precise")
end
add_packages("gmp")
if is_mode("debug") then
Expand Down
Loading