-
Notifications
You must be signed in to change notification settings - Fork 0
/
bvec.rkt
39 lines (32 loc) · 1021 Bytes
/
bvec.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#lang racket/base
(require (except-in ffi/unsafe ->)
ffi/vector
glm/private/vector
racket/contract
racket/function)
(provide (except-out (all-defined-out) current-bvec-precision))
(provide (all-defined-out))
(define-vector-type bvec _int boolean? exact-integer? equal?
#:from-scalar values
#:to-scalar (λ (a) (if a 1 0))
#:to-native (λ (x) (= x 1))
#:fill #f
#:ffi s32vector)
(define/contract bvec-and (-> bvec? bvec? ... bvec?)
(case-lambda
[(v) v]
[(v1 v2 . vs)
(apply bvec-and (for/bvec ([x1 (in-bvec v1)]
[x2 (in-bvec v2)])
(and x1 x2))
vs)]))
(define/contract bvec-or (-> bvec? bvec? ... bvec?)
(case-lambda
[(v) v]
[(v1 v2 . vs)
(apply bvec-or (for/bvec ([x1 (in-bvec v1)]
[x2 (in-bvec v2)])
(or x1 x2))
vs)]))
(define/contract (bvec-not v) (-> bvec? bvec?)
(for/bvec ([x (in-bvec v)]) (not x)))