English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
if (n:int) < 0 then (-n) > 0 is FALSE
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-12-08 (18:20)
From: Mattias_Engdegård <mattias@v...>
Subject: Re: [Caml-list] if (n:int) < 0 then (-n) > 0 is FALSE
>I wouldn't call it a bug. It looks like modulo arithmetic to me.

Let's not make a virtue of necessity. The type "int" was likely designed
with the intent to provide a type that could be used for actual integers
in a variety of circumstances, while giving good performance. The modulo
semantics is rarely useful (especially the 30-bit signed variety) but
is the price paid for reasonable performance with a simple implementation.

>> I would love to have a fast unboxed integer type that automatically
>> overflows to bignum, but it would be a tad slower than the current "int".
>How can it be both unboxed and allow overflow to a bignum? Would you generate 
>int and bigint versions of all functions and then bail to the bigint version 
>if anything overflowed?

This is just what Lisp implementations have done for decades.

Yes, it means that code must be prepared to handle either version
(unless the compiler can prove that this is not necessary).
Generating two versions of all functions is neither necessary nor sufficient.