negative?(3scm)
π 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 zeropositive?β tests if the number is greater than zeronegative?β tests if the number is less than zeroodd?β tests if the number is oddeven?β 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
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2022 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms