REAL with generics constraint

"Arnaud Payement" <[email protected]>
Newsgroups gmane.comp.lang.eiffel.smalleiffel
Message-ID <[email protected]>
 

 I am using eiffel to write a VECTOR class with operation like dot and cross
products and I need to get the norm of the vector. Therefore, I am using the
sqrt methods of the REAL type. However, I want to use my class with REAL_32
or REAL_64 etc . I use generics with constraint but REAL_64 and REAL_32
doesn't have a root class with the sqrt methods !!!!!! How can I do that ? I
am new to Eiffel, so my question is perhaps a stupid one. My code : 

 

 

class VECTOR[T -> ???????????????????]

 

creation {ANY}

            make

 

feature {VECTOR}

            dimension: INTEGER

 

            coord: NATIVE_ARRAY[T]

 

feature {ANY} 

            make (dim: INTEGER) is

                        require

                                   dim > 0

                        do

                                   dimension := dim

                                   coord := coord.calloc(dimension)

                        ensure

                                   dimension > 0

                        end

 

            infix "+" (other: like Current): like Current is

                        require

                                   other.dimension = dimension

                        local

                                   res: like Current; i: INTEGER

                        do

                                   create res.make(dimension)

                                   from

                                               i := 0

                                   until

                                               i < dimension

                                   loop

                                               res.coord.put(coord.item(i) +
other.coord.item(i), i)

                                               i := i + 1

                                   end

                                   Result := res

                        ensure

                                   Result.dimension = dimension

                        end

 

            infix "-" (other: like Current): like Current is

                        require

                                   other.dimension = dimension

                        local

                                   res: like Current; i: INTEGER

                        do

                                   create res.make(dimension)

                                   from

                                               i := 0

                                   until

                                               i < dimension

                                   loop

                                               res.coord.put(coord.item(i) -
other.coord.item(i), i)

                                               i := i + 1

                                   end

                                   Result := res

                        ensure

                                   Result.dimension = dimension

                        end

 

            infix "|" (other: like Current): T is

                                   -- surcharge de l'operateur |

                        require

                                   other.dimension = dimension

                        local

                                   res: T; i: INTEGER

                        do

                                   from

                                               i := 0

                                   until

                                               i < dimension

                                   loop

                                               res := res + coord.item(i) *
other.coord.item(i)

                                               i := i + 1

                                   end

                                   Result := res

                        end

 

            set_item (i: INTEGER; val: T) is

                        require

                                   0 <= i and i < dimension

                        do

                                   coord.put(val, i)

                        end

 

            get_item (i: INTEGER): T is

                        require

                                   0 <= i and i < dimension

                        do

                                   Result := coord.item(i)

                        end

 

            get_dimension: INTEGER is

                        do

                                   Result := dimension

                        end

 

            get_norm: T is

                        do

                                   Result := (Current|Current).sqrt

                        end

 

end
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.