Can't understand this

1 message Options
Embed this post
Permalink
Chris Saunders-4

Can't understand this

Reply Threaded More More options
Print post
Permalink
I'm resending this question.  I had a reply to this question from Manu and
have made some changes to the code that should address that reply.  I'm
going to show what I think is the minimal amount of code that will
demonstrate the problem.  First class INT_8_REF which has a lot of its code
removed:

class
 INT_8_REF

inherit
 ALGEBRAIC_NUMBER [INTEGER_8]
  undefine
   is_equal
  redefine
   default_create
  end

 COMPARABLE
  undefine
   copy,
   out
  redefine
   default_create
  end

 INTEGRAL_DOMAIN [INTEGER_8]
  undefine
   copy,
   is_equal,
   out
  redefine
   default_create,
   field_quotient
  end

create
 default_create, make

feature {NONE} -- Initialization

 default_create
   -- Default initialization for current object.
   -- Set `field_epsilon' to `Default_field_epsilon'.
  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'.
   -- Set `field_epsilon' to `Default_field_epsilon'.
  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'.
   -- Set `field_epsilon' to `Default_field_epsilon'.
  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

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

feature -- Access

 Default_field_epsilon: REAL_64
   -- Default `epsilon' used for FIELD_64s.
   -- Value is 2.2204460492503131e-016.
  once
   Result := Dbl_epsilon
  end

 field_epsilon: REAL_64 assign set_field_epsilon
   -- `epsilon' used for FIELD_64s.

feature -- Element change

 set_field_epsilon (v: like field_epsilon)
   -- Set `field_epsilon' to `v'.
  do
   field_epsilon := v
  ensure
   field_epsilon_ser: field_epsilon = v
  end

feature {NONE} -- Externals

 Dbl_epsilon: REAL_64
   -- Smallest such that 1.0 + `Dbl_epsilon' /= 1.0.
   -- Value is 2.2204460492503131e-016.
  external
   "C inline use <float.h>"
  alias
   "[
    return DBL_EPSILON
   ]"
  end

invariant
 field_epsilon_large_enough: field_epsilon >= Default_field_epsilon

end

Next I'll show the entire INT_8 class because it is very short:

expanded class
 INT_8

inherit
 INT_8_REF

create
 default_create,
 make,
 make_from_integer,
 make_from_reference

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

end

Now from my testing code here is an excerpt:

   e := -2
   print ("e.field_epsilon = "); print (e.field_epsilon); cr
   f := 7
   print ("f.field_epsilon = "); print (f.field_epsilon); crr
   e.field_epsilon := 0.00000000000005
   f.field_epsilon := 0.00000000000005

   print ("e = "); print (e); cr
   print ("e.Default_field_epsilon = "); print (e.Default_field_epsilon); cr
   print ("e.field_epsilon = "); print (e.field_epsilon); cr

Here is the output of the above section of code:

e.field_epsilon = 0
f.field_epsilon = 0

e = -2
e.Default_field_epsilon = 2.2204460492503131e-016
e.field_epsilon = 5.0000000000000002e-014

By the way, I have been running this code with invariant assertions turned
off so I could get this output. Otherwise `field_epsilon_large_enough' is
thrown.

Note "e.field_epsilon = 0" should not occur because of the convesion clause
"make_from_integer" in INT_8 and `make_from_integer' sets this value.  I
don't see that it is even possible to create an INT_8 with `field_epsilon'
set to 0.  Note the correspondence between the creation clauses of INT_8 and
the initialization features of class INT_8_REF.  I'm still inclined to make
a bug report for this and am looking for some conformation that it looks
like I should.

Sorry if this is a little long, I have tried to keep it as short as I could.

Regards
Chris Saunders