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

Tree @master (Download .tar.gz)

lt-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
-->

### `lt?` ###

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

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

    | (lt? 6 4)
    = #f

    | (lt? 6 8)
    = #t

    | (lt? 6 6)
    = #f

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

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

    | (lt? 2147483646 2147483647)
    = #t

    | (lt? 1 2147483647)
    = #t

    | (lt? (subtract 0 2147483647) (subtract 0 2147483646))
    = #t

    | (lt? (subtract 0 2147483647) (subtract 0 1))
    = #t

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

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

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

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

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

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

'<<SPEC'

(define lt? (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 (subtract 0 1))
      (cmp-same-sign? (subtract (sign a) 1) (subtract (sign b) 1) (subtract 0 1))))))