git @ Cat's Eye Technologies Robin / master stdlib / gt-p.robin
master

Tree @master (Download .tar.gz)

gt-p.robin @masterraw · history · blame

;'<<SPEC'

<!--
Copyright (c) 2012-2024, Chris Pressey, Cat's Eye Technologies.
This file is distributed under a 2-clause BSD license.  See LICENSES/ dir.
SPDX-License-Identifier: LicenseRef-BSD-2-Clause-X-Robin
-->

### `gt?` ###

    -> Tests for functionality "Evaluate Robin Expression (with Arith)"

`gt?` evaluates both of its arguments to numbers, then evaluates to `#t`
if the first number is strictly greater than the second.

    | (gt? 6 4)
    = #t

    | (gt? 6 8)
    = #f

    | (gt? 6 6)
    = #f

    | (gt? 1610612736 (subtract 0 1610612736)))
    = #t

    | (gt? (subtract 0 1610612736) 1610612736)
    = #f

    | (gt? 2147483646 2147483647)
    = #f

    | (gt? 1 2147483647)
    = #f

    | (gt? (subtract 0 2147483647) (subtract 0 2147483646))
    = #f

    | (gt? (subtract 0 2147483647) (subtract 0 1))
    = #f

    | (gt? 0 (subtract (subtract 0 1073741824) 1073741824)))
    = #t

`gt?` expects exactly two arguments, both numbers.

    | (gt? 14)
    ? abort (illegal-arguments

    | (gt? 14 23 57)
    ? abort (illegal-arguments

    | (gt? 14 #t)
    ? abort (expected-number #t)

    | (gt? #t 51)
    ? abort (expected-number #t)

'<<SPEC'

(define gt? (fun (a b)
  (bind cmp-same-sign? (fun (a b c)
    (equal? (sign (subtract a b)) c))
    (if (equal? (sign a) (sign b))
      (cmp-same-sign? a b 1)
      (cmp-same-sign? (subtract (sign a) 1) (subtract (sign b) 1) 1)))))