Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

/**

* This modules defines operations on integers, which are guaranteed to be at

* least 31 bits wide (including the sign bit)

*

* @category data

* @destination public

* @author Valentin Gatien-Baron, 2010 (documentation)

* @author Nicolas Pelletier, 2010

* @stability stable

**/

/**

* {1 About this module}

*

* {1 Where should I start?}

*

* {1 What if I need more?}

*/

/**

* {1 Types defined in this module}

*/

/**

* Order type label for int and float

*/

typeInt.order = Order.default

typeFloat.order = Order.default

/**

* {1 Interface}

*/

Int = {{

/**

* {2 Numeric operations}

*/

/**

* The standard addition

*/

add = %% BslPervasives.int_add %% : int, int -> int

/**

* The standard subtracion

*/

sub = %% BslPervasives.int_sub %% : int, int -> int

/**

* The standard multiplication

*/

mul = %% BslPervasives.int_mul %% : int, int -> int

/**

* The standard quotient

*/

div = %% BslPervasives.int_div %% : int, int -> int

/**

* {2 Order}

*/

order = Order.make(ordering) : order(int, Int.order)

/**

* Compare two int

*/

compare_raw = %% BslPervasives.compare_int %%

ordering = %% BslNumber.Int.ordering %%

compare(x,y): Order.comparison =

@opensums(ordering(x,y))

`!=` = %% BslPervasives.int_cmp_neq %% : int, int -> bool

`==` = %% BslPervasives.int_cmp_eq %% : int, int -> bool

`<` = %% BslPervasives.int_cmp_lneq %% : int, int -> bool

`<=` = %% BslPervasives.int_cmp_leq %% : int, int -> bool

`>` = %% BslPervasives.int_cmp_gneq %% : int, int -> bool

`>=` = %% BslPervasives.int_cmp_geq %% : int, int -> bool

`+` = %% BslPervasives.int_add %%

`-` = %% BslPervasives.int_sub %%

`*` = %% BslPervasives.int_mul %%

`/` = %% BslPervasives.int_div %%

/**

* Add 1 to the int given in parameter

*/

succ(i) = i+1

/**

* Subtract 1 to the int given in parameter

*/

pred(i) = i-1

/**

* Check equality of two int

*/

equals = %% BslPervasives.int_cmp_eq %% : int, int -> bool

/**

* {2 Conversion functions}

*/

/**

* Returns the string representation of the integer

*/

to_string = String.of_int : int -> string

/**

* Parse a string as an int

* The usage of this function is discouraged, as it will exit with an error

* when the input is incorrect

* It should be used only in parsers, where you can be sure that the string is