Skip to content

Number

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (number? <value>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “<output>”.

valueoutput
#fB
’()B
0A
42A
-2045A

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (<predicate> <value>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “<output>”.

predicatevalueoutput
zero?0A
zero?1B
positive?42A
positive?-42B
negative?-42A
negative?42B
even?2A
even?3B
odd?3A
odd?2B

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (<predicate> <value>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “<output>”.

predicatevalueoutput
number?0A
number?1A
number?-42A
complex?0A
complex?1A
complex?-42A
real?0A
real?1A
real?-42A
rational?0A
rational?1A
rational?-42A
integer?0A
integer?1A
integer?-42A

Check a number class of floating point numbers

Section titled “Check a number class of floating point numbers”

Given a file named “main.scm” with:

(import (scheme base) (scheme inexact))
(write-u8 (if (<predicate> <value>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “<output>”.

predicatevalueoutput
number?3.14A
number?-42.2045A
complex?3.14A
complex?-42.2045A
real?3.14A
real?-42.2045A
rational?0A
rational?1A
rational?-42A
rational?3.14A
rational?-42.2045A
rational?(exp 1)A
integer?3.14B
integer?-42.2045B

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (<predicate> #f) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “B”.

predicate
number?
complex?
real?
rational?
integer?

Given a file named “main.scm” with:

(import (scheme base))
(define x <value>)

When I successfully run stak main.scm

Then the exit status should be 0.

value
0
1
42
-1
-42

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (+ 66 -1))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (- 1065 1000))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (- <value> 60))

When I successfully run stak main.scm

Then the stdout should contain exactly “<output>”.

valueoutput
127C
128D
129E

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= <expression> <value>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

expressionvalue
(+)0
(+ 1)1
(+ 1 2)3
(- 1)-1
(- 0 1)-1
(- 0 1 2)-3
(*)1
(* 2)2
(* 2 3)6
(/ 6 2)3
(/ 6 2 3)1

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= <expression> <value>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

expressionvalue
(quotient 6 2)3
(quotient 6 3)2
(quotient -6 2)-3
(quotient -6 -2)3
(truncate-quotient 6 2)3
(truncate-quotient 6 3)2
(truncate-quotient -6 2)-3
(truncate-quotient -6 -2)3
(remainder 8 3)2
(remainder 8 -3)2
(remainder -8 3)-2
(remainder -8 -3)-2
(truncate-remainder 8 3)2
(truncate-remainder 8 -3)2
(truncate-remainder -8 3)-2
(truncate-remainder -8 -3)-2
(modulo 5 1)0
(modulo 5 2)1
(modulo 8 3)2
(modulo 8 -3)-1
(modulo -8 3)1
(modulo -8 -3)-2
(floor-remainder 5 1)0
(floor-remainder 5 2)1
(floor-remainder 5 3)2
(floor-remainder -5 2)1
(floor-remainder -5 -2)-1

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (/ 2) (/ 1 2)) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base) (scheme inexact))
(write-u8 (if (< (abs (- (expt 2 3) (exp (* (log 2) 3)))) 0.000001) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base) (scheme inexact))
(write-u8 (if (< (abs (- (log 2 3) (/ (log 2) (log 3)))) 0.000001) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base) (scheme inexact))
(write-u8 (if (= (truncate <input>) <output>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

inputoutput
00
0.10
0.90
11
1.11
1.91
22
-0.90
-1-1
-1.9-1
-2-2
-2.1-2

Given a file named “main.scm” with:

(import (scheme base) (scheme inexact))
(write-u8 (if (= (floor <input>) <output>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

inputoutput
00
0.10
0.90
11
1.11
1.91
22
-0.9-1
-1-1
-1.9-2
-2-2
-2.1-3

Given a file named “main.scm” with:

(import (scheme base) (scheme inexact))
(write-u8 (if (= (ceiling <input>) <output>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

inputoutput
00
0.11
0.91
11
1.12
1.92
22
-0.90
-1-1
-1.9-1
-2-2
-2.1-2

Given a file named “main.scm” with:

(import (scheme base) (scheme inexact))
(write-u8 (if (= (round <input>) <output>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

inputoutput
00
0.10
0.490
0.50
0.91
11
1.11
1.491
1.52
1.92
22
2.52
3.54
-1-1
-0.9-1
-1.5-2
-1.51-2
-1.9-2

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if <expression> 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

expression
(< 0 1)
(< 0 1 2)
(> 1 0)
(<= 0 1)
(<= 0 0)
(>= 1 0)
(>= 0 0)

Compare numbers with an insufficient number of arguments

Section titled “Compare numbers with an insufficient number of arguments”

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (< <values>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

values
0

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (min <values>) <output>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

valuesoutput
00
11
1 21
1 2 31
2 3 11
3 1 21

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (max <values>) <output>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

valuesoutput
00
11
1 22
1 2 33
2 3 13
3 1 23

Given a file named “main.scm” with:

(import (scheme base))
(write-string (number->string <value> <radix>))

When I successfully run stak main.scm

Then the stdout should contain exactly “<output>”.

valueradixoutput
00
11
22
4242
-1-1
-2-2
-42-42
0160
1161
2162
1516f
42162a
-116-1
-216-2
-4216-2a
0320
1321
2322
3132v
42321a
-132-1
-232-2
-4232-1a

Convert a floating point number to a string

Section titled “Convert a floating point number to a string”

Given a file named “main.scm” with:

(import (scheme base))
(write-string (number->string <value>))

When I successfully run stak main.scm

Then the stdout should contain “<value>”.

value
0.5
0.125
1.2
3.14
-3.14

Given a file named “main.scm” with:

(import (scheme base))
(write-string (number->string (string->number "<value>" <radix>)))

When I successfully run stak main.scm

Then the stdout should contain exactly “<output>”.

valueradixoutput
00
11
22
4242
-1-1
-2-2
-42-42
0160
1161
2162
f1615
2a1642
2A1642
-116-1
-216-2
-2a16-42
-2A16-42
0320
1321
2322
v3231
1a3242
1A3242
-132-1
-232-2
-1a32-42
-1A32-42

Convert a string to a floating point number

Section titled “Convert a string to a floating point number”

Given a file named “main.scm” with:

(import (scheme base))
(write-string (number->string (string->number "<value>")))

When I successfully run stak main.scm

Then the stdout should contain exactly “<value>”.

value
0.5
0.125
1.2
3.14
-3.14

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (string->number "<value>") 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “B”.

value
x
foo
-
2x
-x
-2x