Skip to content

Floating-point number

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) (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

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

Convert a non-finite floating point number to a string

Section titled “Convert a non-finite 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 “<output>”.

valueoutput
(/ 0 0)nan
(/ 1 0)infinity
(/ -1 0)-infinity

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) (scheme inexact))
(write-u8
(if (< (abs (- (expt (sqrt <value>) 2) <value>)) 0.001)
65
66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

value
0
1
2
42

Given a file named “main.scm” with:

(import (scheme base) (scheme inexact))
(write-u8
(if (< (abs (- (/ (sin <value>) (cos <value>)) (tan <value>))) 0.001)
65
66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

value
-2
-1
0
1
2

Given a file named “main.scm” with:

(import (scheme base) (scheme complex) (scheme inexact))
(write-u8
(if (= (round (real-part (<normal> (<inverse> 1)))) 1)
65
66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

normalinverse
cosacos
sinasin
tanatan