comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: can Ada give run-time error or warning for integer division with non-zero remainder?
Date: Sun, 12 Aug 2012 08:45:03 +0200
Date: 2012-08-12T08:45:03+02:00	[thread overview]
Message-ID: <6w1edbm9sq16.1b2o3nufa2r0p.dlg@40tude.net> (raw)
In-Reply-To: k07028$eok$1@speranza.aioe.org

On Sat, 11 Aug 2012 20:14:42 -0500, Nasser M. Abbasi wrote:

> In Ada when dividing 2 integers, the result is an integer
> with the remainder ignored.  Hence 3/2 gives 1
> 
> ----------------------------------
> with Ada.Integer_Text_IO ; use Ada.Integer_Text_IO ;
> 
> procedure foo4 is
>    N : constant integer := 3;
>    M : integer;
>    
>    begin
>      M := N/2;
>      put(M);
>         
> end foo4;
> --------------------------
> 
>>gnatmake foo4.adb
>>./foo4
>            1
> Now, suppose I want to know that a division between 2 integers
> has resulted in nonzero remainder that was thrown away. May be
> because my algorithm is meant to work only for even values and
> an odd value means there was a bug somewhere and I want to
> know about it.

It is not integer division then. You could use integer interval division
instead: [3, 3] / [2, 2] = [1, 2].

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2012-08-12  6:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-12  1:14 can Ada give run-time error or warning for integer division with non-zero remainder? Nasser M. Abbasi
2012-08-12  5:45 ` J-P. Rosen
2012-08-12  6:45 ` Dmitry A. Kazakov [this message]
2012-08-12  7:16 ` Per Sandberg
2012-08-12 14:03   ` Brad Moore
2012-08-12 14:19 ` Robin Vowels
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox