Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
unsigned comparisons on int32, int64, nativeint?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-01-21 (21:21)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: unsigned comparisons on int32, int64, nativeint?
> I have sought but not found unsigned comparisons on the integer types
> int32, int64, and nativeint.  I especially need `unsigned less than'.
> Where might I find bindings for these operations?

In a pinch, you can always use signed compares after shifting the
arguments by min_int, e.g.:

let ule_int32 a b = Int32.add a Int32.min_int <= Int32.add b Int32.min_int

(I have a very strong feeling that it should work, but no doubt
expert bit-twiddlers on this list will correct me if it doesn't.)

The code generated for this is nowhere as efficient as a
processor-native unsigned comparison, though.  

- Xavier Leroy