On Sat, Jul 16, 2016 at 1:04 PM, Thomas Chust <[email protected]> wrote: > On 2016-07-16 21:31, Matt Welland wrote: > > [...] > > (define (vg:rgb->number r g b #!key (a 0)) (u32vector-ref > > (blob->u32vector (u8vector->blob (list->u8vector (list a r g b)))) 0)) > > [...] > > Hello, > > this snippet seems somewhat sub-optimal to say the least. Apart from > being needlessly complicated, it may also be wrong because its result > depends on the endianness of the host platform. > > I would suggest to simply use bitwise arithmetic: > > (bitwise-ior > (arithmetic-shift a 24) > (arithmetic-shift r 16) > (arithmetic-shift g 8) > b) >
Nice. Blindingly obvious now that it has been pointed out. Interestingly enough it also appears to be 4x faster. Thanks! > Or perhaps just normal arithmetic replacing bitwise-ior by + and > arithmetic-shift by (lambda (x n) (* x (expt 2 n))). This is probably no > less efficient, as the result is going to be a bignum anyway. > > Ciao, > Thomas > > > -- > When C++ is your hammer, every problem looks like your thumb. > > _______________________________________________ > Chicken-users mailing list > [email protected] > https://lists.nongnu.org/mailman/listinfo/chicken-users >
_______________________________________________ Chicken-users mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/chicken-users
