octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: checked int-int conversions


From: John W. Eaton
Subject: Re: checked int-int conversions
Date: Wed, 30 Jul 2008 15:42:29 -0400

On 30-Jul-2008, Jaroslav Hajek wrote:

| On Wed, Jul 30, 2008 at 9:08 PM, John W. Eaton <address@hidden> wrote:
| > On 30-Jul-2008, Jaroslav Hajek wrote:
| >
| > | please consider for applying the attached patch that implements
| > | checked integer conversions - applies to converting
| > | octave_int<T>, intXXNDArray and octave_intXX_matrix objects, as well
| > | as Octave's builtin intXX and uintXX conversions.
| >
| > OK, now I'm a bit confused because I was expecting a much smaller
| > change that would just add some warning if an attempt was made to
| > convert a value to native int and the value was out of range.  Can you
| > give some details about the intent of this patch?
| >
| > Thanks,
| >
| > jwe
| >
| 
| OK. As I have commented in the earlier thread, Octave's intX and uintX
| builtins also do not give a warning when truncating:
| a = int32 (2^30); b = int16 (a)
| Neither is a warning issued if, e.g. int8_array_value () is called on
| a octave_int32_matrix object.
| 
| I've added a static flag to the octave_int<T> class that gets enabled
| when data are truncated by the conversion constructor. The
| intY_array_value methods of octave_intX_matrix classes check the flag
| after the conversion and issue a warning when truncation occured.
| I've also modified the conversion operators in ops.h to ask the
| octave_value object directly for the required type instead of doing
| the conversion themselves. This makes the intX and uintX builtins warn
| if truncation is done:
| 
| a = int32 (2^30); b = int16 (a)
| warning: data truncated converting from int32 to int16
| 32767
| 
| a warning is also issued if negative intX is converted to uintX.

OK, now I also see that Matlab has a similar optional warning.  I'll
apply the patch.

In Matlab, the warning is controlled with the warning ID
MATLAB:intConvertOverflow.  Should we use the same tag (but with an
Octave: prefix)?  Then if we also modified the warning_with_id
function to convert a "MATLAB:" warning ID prefix to "Octave:" before
comparing IDs it would be easier to write portable code.

Thanks,

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]