WhileyCompiler icon indicating copy to clipboard operation
WhileyCompiler copied to clipboard

Semantics of Division and Remainder?

Open DavePearce opened this issue 3 years ago • 0 comments

Currently, the following passes verification:

  assert (-6) / 4 == -2
  assert (-6) % 4 == 2

However, they fail runtime checking! In contrast, the following pass runtime checking but fail verification:

   assert (-6) / 4 == -1
   assert (-6) % 4 == -2

The latter is what I would expect from a reasonable programming language, whilst the former is nuts.

NOTE: The reason this is happening is almost certainly due to the semantics implemented by Boogie. For example, Dafny exhibits the same behaviour (which it refers to as Euclidean division).

ALSO: The languages java, rust, go and solidity (amongst others) all follow non-Euclidean division (like the runtime semantics of Whiley). Therefore, its pretty clear which is the right semantic!!

DavePearce avatar Jul 06 '22 00:07 DavePearce