Can't understand this

3 messages Options
Embed this post
Permalink
Chris Saunders-4

Can't understand this

Reply Threaded More More options
Print post
Permalink
I'm searching for bugs in the latest version of EiffelStudio 6.5 and think I
may have found one but am not sure of this.  I'm going to show as little
code as I think will show the problem:

Here are the creation procedures of class INT_8_REF:


 default_create
   -- Default initialization for current object.
  do
   field_epsilon := Default_field_epsilon
  ensure then
   field_epsilon_set: field_epsilon = Default_field_epsilon
  end

 make (v: INTEGER_8)
   -- Initialization for `Current'.
   -- Set item to `v'.
  do
   item := v
   field_epsilon := Default_field_epsilon
  ensure
   item_set: item = v
   field_epsilon_set: field_epsilon = Default_field_epsilon
  end

 make_from_integer (v: INTEGER)
   -- Initialization for `Current'.
   -- Set item to `v'.
  require
   v_small_enough: v <= {INTEGER_8}.Max_value
   v_large_enough: v >= {INTEGER_8}.Min_value
  do
   item := v.to_integer_8
   field_epsilon := Default_field_epsilon
  ensure
   item_set: item = v.to_integer_8
   field_epsilon_set: field_epsilon = Default_field_epsilon
  end

I have an expanded class called INT_8, it is simple so here is the whole
thing:

expanded class
 INT_8

inherit
 INT_8_REF

create
 default_create,
 make,
 make_from_integer

convert
 make ({INTEGER_8}),
 make_from_integer ({INTEGER}),
 to_integer_8: {INTEGER_8}

end

I have an object in my root class declared as "e: INT_8".  I am assignint it
as "e := -2" and then am doing "print ("e.field_epsilon = "); print
(e.field_epsilon); cr".  The result of the last line is printed as "0".
Note that in `make_from_integer', `field_epsilon' is set to
`Default_field_epsilon' which is declared in INT_8_REF as
`Default_field_epsilon: REAL_64 = 0.00000000000000005'.

Sorry, this is a little longer than I had hoped.  Does any one else think
this is a bug.  I'm inclined to make a bug report but don't feel certain
enough that this is one.

Regards
Chris Sauners

Emmanuel Stapf

RE: Can't understand this

Reply Threaded More More options
Print post
Permalink
> as "e := -2" and then am doing "print ("e.field_epsilon = "); print
> (e.field_epsilon); cr".  The result of the last line is printed as "0".
> Note that in `make_from_integer', `field_epsilon' is set to
> `Default_field_epsilon' which is declared in INT_8_REF as
> `Default_field_epsilon: REAL_64 = 0.00000000000000005'.

The issue is that the value has 17 digits and a REAL_64 can only hold 16
significant digits. Rewriting the constant as 5.0e-17 should give you the proper
value.

Regards,
Manu

------------------------------------------------------------------------  
Eiffel Software
805-685-1006
http://www.eiffel.com       
Customer support: http://support.eiffel.com       
User group: http://groups.eiffel.com/join       
------------------------------------------------------------------------  
Chris Saunders-4

Re: Can't understand this

Reply Threaded More More options
Print post
Permalink
Thanks for the response Manu.  I'm wondering if you are correnct because of
this output from my tests "e.Default_field_epsilon =
4.9999999999999999e-017".  I did attempt the fix you suggested and still got
the same result except tht Default_field_epsilon is more accurate
"e.Default_field_epsilon = 5.0000000000000005e-017".  I'll remind you that I
think the bug is that after this assignment "e := -2" the output of
`field_epsilon' from `e' is still "0".  Do you think maybe this is a bug?

Regards
Chris Saunders

----- Original Message -----
From: Emmanuel Stapf [ES]
To: [hidden email]
Sent: Sunday, August 30, 2009 11:49 PM
Subject: RE: [eiffel_software] Can't understand this


  > as "e := -2" and then am doing "print ("e.field_epsilon = "); print
> (e.field_epsilon); cr". The result of the last line is printed as "0".
> Note that in `make_from_integer', `field_epsilon' is set to
> `Default_field_epsilon' which is declared in INT_8_REF as
> `Default_field_epsilon: REAL_64 = 0.00000000000000005'.

The issue is that the value has 17 digits and a REAL_64 can only hold 16
significant digits. Rewriting the constant as 5.0e-17 should give you the
proper
value.

Regards,
Manu