negative?(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

πŸ’… negative?(3scm) ✨

okay so this is a page from the Scheme Programmer's Manual and it's literally all about the numerical predicates β€” the little vibe-check functions that look at a number and go "yeah" or "nope" πŸŽ€


🌸 NAME

negative?, positive?, odd?, even?, flnegative?, flpositive?, flodd?, fleven?, fxnegative?, fxpositive?, fxodd?, fxeven? β€” the numerical predicates, periodt πŸ‘‘


πŸ“š LIBRARY

here's where you import these besties from, iykyk:

(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS
(import (rnrs arithmetic flonums))  ;R6RS
(import (rnrs arithmetic fixnums))  ;R6RS

✨ SYNOPSIS

(negative? x)
(positive? x)
(odd? n)
(even? n)

;; R6RS
(flnegative? fl)
(flpositive? fl)
(flodd? fl)
(fleven? fl)
(fxnegative? fx)
(fxpositive? fx)
(fxodd? fx)
(fxeven? fx)

πŸ’– DESCRIPTION

So these are the numerical predicates β€” they take a number object, check it for one specific property, and hand you back #t or #f. that's it, that's the whole job 🫢

πŸ” Properties tested

the predicates check these properties, no cap:

  • zero? β€” tests if the number is = to zero
  • positive? β€” tests if the number is greater than zero
  • negative? β€” tests if the number is less than zero
  • odd? β€” tests if the number is odd
  • even? β€” tests if the number is even

πŸ¦‹ Flonum variants

these variants are picky β€” they restrict their arguments to flonums only, respectfully πŸ’…

πŸŽ€ Fixnum variants

same energy, different lane: these variants restrict their arguments to fixnums.

⚠️ heads up bestie: unless the number is exact, the results may be unreliable, because a tiny little inaccuracy can straight up flip the answer. so like… be careful with your inexact numbers fr fr 😭

🌈 RETURN VALUES

returns a single value β€” a boolean. iconic behavior, honestly.


⭐ EXAMPLES

(zero? +0.0)        =>  #t
(zero? -0.0)        =>  #t
(zero? +nan.0)      =>  #f
(positive? +inf.0)  =>  #t
(negative? -inf.0)  =>  #t
(positive? +nan.0)  =>  #f
(negative? +nan.0)  =>  #f

🧚 COMPATIBILITY

these procedures work the same in all Scheme revisions since R2RS. consistent queen behavior since day one πŸ‘‘


πŸ’€ ERRORS

this procedure can raise exceptions with the following condition types:

  • &assertion (R6RS) β€” the wrong number of arguments was passed, or an argument was outside its domain.
  • R7RS β€” the assertions described above are errors. implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically. πŸ™ˆ yeah, catastrophically. not a drill.

πŸ”₯ SEE ALSO

>(3scm), finite?(3scm)


πŸ† STANDARDS

R4RS, IEEE Scheme, R5RS, R6RS, R7RS


πŸ•°οΈ HISTORY

these procedures were first introduced in R2RS. Scheme before then, running on MacLisp, had access to similar predicates: zerop, plusp, minusp, and oddp. LISP 1.5 had a minusp predicate that returned true for negative numbers, including -0. it also had zerop and onep predicates. these were specified to be true when the absolute difference between the argument and zero or one, respectively, is less than 3e-6. so yeah, history was doing its own thing πŸ’œ


πŸ‘‘ AUTHORS

this page is part of the scheme-manpages project. it includes materials from the RnRS documents. more info lives at https://github.com/schemedoc/manpages/.


🌸 okay that's the whole page!! sourced from the scheme-manpages project, dated 2022-05-10, and honestly? ate. go forth and predicate, bestie πŸ’–βœ¨

πŸ“¦ where this page comes from