checked int-int conversions
Jaroslav Hajek
highegg at gmail.com
Wed Jul 30 14:29:35 CDT 2008
On Wed, Jul 30, 2008 at 9:08 PM, John W. Eaton <jwe at bevo.che.wisc.edu> 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.
regards
--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
More information about the Octave-maintainers
mailing list