Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

writing negative numbers in racket

Tags:

scheme

racket

2 – (-12/x) = -4

the negative 12 is what is confusing me. where do I put the negative sign?

(define (math x)
( = ( - ( / 12 x) 2) 4))
like image 380
Josh Avatar asked Oct 27 '25 07:10

Josh


1 Answers

The negative symbol is a part of the number itself, you write it like you would in any other language:

(define (math x)
( = ( - ( / -12 x) 2) 4))

Output:

> (math 2)  ; 2-(-12/2) = -4 -> 2-(-6) = -4 -> 2 + 6 = -4 -> 8 = -4 (FALSE)
#f
> (math -2) ; 2-(-12/-2) = -4 -> 2-(6) = -4 -> -4 = -4 (TRUE)
#t
like image 179
Hunter McMillen Avatar answered Oct 30 '25 00:10

Hunter McMillen