Wondering about this

6 messages Options
Embed this post
Permalink
Chris Saunders-4

Wondering about this

Reply Threaded More More options
Print post
Permalink
In class SINGLE_MATH sqrt is defined like this:

 sqrt (v: REAL): REAL
   -- Square root of `v'
  require
   v >= 0.0
  external
   "C signature (double): double use <math.h>"
  alias
   "sqrt"
  end

I have a class where I define +infinity like this:

 Positive_infinity: REAL_32
   -- Positive infinity.
  local
   n, d: REAL_32
  once
   n := {REAL_32}1.0
   Result := n / d
  end

Now if I call `sqrt' from SINGLE_MATH with the above `Positive_infinity' I
get the error "Precondition violated." from SINGLE_MATH.  Does this seem
correct?

Regards
Chris Saunders

rfo

RE: Wondering about this

Reply Threaded More More options
Print post
Permalink
Hi Chris!

My guess is because 1.0/0.0 is a NAN (not a number) and if used in most
fp ops will raise an FPE (floating point exception)


     R

==================================================
Roger F. Osmond


> -------- Original Message --------
> Subject: [eiffel_software] Wondering about this
> From: "Chris Saunders" <[hidden email]>
> Date: Sun, October 18, 2009 4:37 am
> To: "Eiffel Software Mailing List" <[hidden email]>
> In class SINGLE_MATH sqrt is defined like this:
>  sqrt (v: REAL): REAL
>    -- Square root of `v'
>   require
>    v >= 0.0
>   external
>    "C signature (double): double use <math.h>"
>   alias
>    "sqrt"
>   end
> I have a class where I define +infinity like this:
>  Positive_infinity: REAL_32
>    -- Positive infinity.
>   local
>    n, d: REAL_32
>   once
>    n := {REAL_32}1.0
>    Result := n / d
>   end
> Now if I call `sqrt' from SINGLE_MATH with the above `Positive_infinity' I
> get the error "Precondition violated." from SINGLE_MATH.  Does this seem
> correct?
> Regards
> Chris Saunders

Chris Saunders-4

Re: Wondering about this

Reply Threaded More More options
Print post
Permalink
Not so Roger.  Here is the output from `Positive_infinity': 1.#INF which
represents +infinity on my machine.  To get NaN one needs to divide 0 by 0.
I believe this would be the case on all machines that use IEEE.

Regards
Chris Saunders

----- Original Message -----
From: [hidden email]
To: [hidden email]
Sent: Sunday, October 18, 2009 9:04 AM
Subject: RE: [eiffel_software] Wondering about this


  Hi Chris!

My guess is because 1.0/0.0 is a NAN (not a number) and if used in most
fp ops will raise an FPE (floating point exception)

R

==================================================
Roger F. Osmond

> -------- Original Message --------
> Subject: [eiffel_software] Wondering about this
> From: "Chris Saunders" <[hidden email]>
> Date: Sun, October 18, 2009 4:37 am
> To: "Eiffel Software Mailing List" <[hidden email]>
> In class SINGLE_MATH sqrt is defined like this:
> sqrt (v: REAL): REAL
> -- Square root of `v'
> require
> v >= 0.0
> external
> "C signature (double): double use <math.h>"
> alias
> "sqrt"
> end
> I have a class where I define +infinity like this:
> Positive_infinity: REAL_32
> -- Positive infinity.
> local
> n, d: REAL_32
> once
> n := {REAL_32}1.0
> Result := n / d
> end
> Now if I call `sqrt' from SINGLE_MATH with the above `Positive_infinity' I
> get the error "Precondition violated." from SINGLE_MATH. Does this seem
> correct?
> Regards
> Chris Saunders


 

carl94706

Re: Wondering about this

Reply Threaded More More options
Print post
Permalink
When I tried this (on a mac with version 6.4) I got an "inf" as a result. No exception.

Carl


--- In [hidden email], "Chris Saunders" <evas@...> wrote:

>
> Not so Roger.  Here is the output from `Positive_infinity': 1.#INF which
> represents +infinity on my machine.  To get NaN one needs to divide 0 by 0.
> I believe this would be the case on all machines that use IEEE.
>
> Regards
> Chris Saunders
>
> ----- Original Message -----
> From: rfo@...
> To: [hidden email]
> Sent: Sunday, October 18, 2009 9:04 AM
> Subject: RE: [eiffel_software] Wondering about this
>
>
>   Hi Chris!
>
> My guess is because 1.0/0.0 is a NAN (not a number) and if used in most
> fp ops will raise an FPE (floating point exception)
>
> R
>
> ==================================================
> Roger F. Osmond
>
> > -------- Original Message --------
> > Subject: [eiffel_software] Wondering about this
> > From: "Chris Saunders" <evas@...>
> > Date: Sun, October 18, 2009 4:37 am
> > To: "Eiffel Software Mailing List" <[hidden email]>
> > In class SINGLE_MATH sqrt is defined like this:
> > sqrt (v: REAL): REAL
> > -- Square root of `v'
> > require
> > v >= 0.0
> > external
> > "C signature (double): double use <math.h>"
> > alias
> > "sqrt"
> > end
> > I have a class where I define +infinity like this:
> > Positive_infinity: REAL_32
> > -- Positive infinity.
> > local
> > n, d: REAL_32
> > once
> > n := {REAL_32}1.0
> > Result := n / d
> > end
> > Now if I call `sqrt' from SINGLE_MATH with the above `Positive_infinity' I
> > get the error "Precondition violated." from SINGLE_MATH. Does this seem
> > correct?
> > Regards
> > Chris Saunders
>


Chris Saunders-4

Re: Re: Wondering about this

Reply Threaded More More options
Print post
Permalink
Sorry Carl it is not clear to me that you called {SINGLE_MATH}.sqrt without
getting this exception.  I did this on Windows Vista and wonder if it is an
operating system issue.

Regards
Chris Saunders


----- Original Message -----
From: carl94706
To: [hidden email]
Sent: Sunday, October 18, 2009 4:07 PM
Subject: [eiffel_software] Re: Wondering about this


  When I tried this (on a mac with version 6.4) I got an "inf" as a result.
No exception.

Carl

--- In [hidden email], "Chris Saunders" <evas@...> wrote:

>
> Not so Roger. Here is the output from `Positive_infinity': 1.#INF which
> represents +infinity on my machine. To get NaN one needs to divide 0 by 0.
> I believe this would be the case on all machines that use IEEE.
>
> Regards
> Chris Saunders
>
> ----- Original Message -----
> From: rfo@...
> To: [hidden email]
> Sent: Sunday, October 18, 2009 9:04 AM
> Subject: RE: [eiffel_software] Wondering about this
>
>
> Hi Chris!
>
> My guess is because 1.0/0.0 is a NAN (not a number) and if used in most
> fp ops will raise an FPE (floating point exception)
>
> R
>
> ==================================================
> Roger F. Osmond
>
> > -------- Original Message --------
> > Subject: [eiffel_software] Wondering about this
> > From: "Chris Saunders" <evas@...>
> > Date: Sun, October 18, 2009 4:37 am
> > To: "Eiffel Software Mailing List" <[hidden email]>
> > In class SINGLE_MATH sqrt is defined like this:
> > sqrt (v: REAL): REAL
> > -- Square root of `v'
> > require
> > v >= 0.0
> > external
> > "C signature (double): double use <math.h>"
> > alias
> > "sqrt"
> > end
> > I have a class where I define +infinity like this:
> > Positive_infinity: REAL_32
> > -- Positive infinity.
> > local
> > n, d: REAL_32
> > once
> > n := {REAL_32}1.0
> > Result := n / d
> > end
> > Now if I call `sqrt' from SINGLE_MATH with the above `Positive_infinity'
> > I
> > get the error "Precondition violated." from SINGLE_MATH. Does this seem
> > correct?
> > Regards
> > Chris Saunders
>


 

carl94706

Re: Wondering about this

Reply Threaded More More options
Print post
Permalink


Here is the code I used:

class
        APPLICATION

inherit
        ARGUMENTS
        SINGLE_MATH

create
        make

feature {NONE} -- Initialization

        make
                        -- Run application.
                local
                        n: REAL_32
                do

                        n := positive_infinity

                        print (sqrt(n).out + "%N")


                end

                Positive_infinity: REAL_32
                   -- Positive infinity.
                  local
                   n, d: REAL_32
                  once
                   n := {REAL_32}1.0
                   Result := n / d
                  end

end

The output is "inf"

Carl



--- In [hidden email], "Chris Saunders" <evas@...> wrote:

>
> Sorry Carl it is not clear to me that you called {SINGLE_MATH}.sqrt without
> getting this exception.  I did this on Windows Vista and wonder if it is an
> operating system issue.
>
> Regards
> Chris Saunders
>
>
> ----- Original Message -----
> From: carl94706
> To: [hidden email]
> Sent: Sunday, October 18, 2009 4:07 PM
> Subject: [eiffel_software] Re: Wondering about this
>
>
>   When I tried this (on a mac with version 6.4) I got an "inf" as a result.
> No exception.
>
> Carl
>
> --- In [hidden email], "Chris Saunders" <evas@> wrote:
> >
> > Not so Roger. Here is the output from `Positive_infinity': 1.#INF which
> > represents +infinity on my machine. To get NaN one needs to divide 0 by 0.
> > I believe this would be the case on all machines that use IEEE.
> >
> > Regards
> > Chris Saunders
> >
> > ----- Original Message -----
> > From: rfo@
> > To: [hidden email]
> > Sent: Sunday, October 18, 2009 9:04 AM
> > Subject: RE: [eiffel_software] Wondering about this
> >
> >
> > Hi Chris!
> >
> > My guess is because 1.0/0.0 is a NAN (not a number) and if used in most
> > fp ops will raise an FPE (floating point exception)
> >
> > R
> >
> > ==================================================
> > Roger F. Osmond
> >
> > > -------- Original Message --------
> > > Subject: [eiffel_software] Wondering about this
> > > From: "Chris Saunders" <evas@>
> > > Date: Sun, October 18, 2009 4:37 am
> > > To: "Eiffel Software Mailing List" <[hidden email]>
> > > In class SINGLE_MATH sqrt is defined like this:
> > > sqrt (v: REAL): REAL
> > > -- Square root of `v'
> > > require
> > > v >= 0.0
> > > external
> > > "C signature (double): double use <math.h>"
> > > alias
> > > "sqrt"
> > > end
> > > I have a class where I define +infinity like this:
> > > Positive_infinity: REAL_32
> > > -- Positive infinity.
> > > local
> > > n, d: REAL_32
> > > once
> > > n := {REAL_32}1.0
> > > Result := n / d
> > > end
> > > Now if I call `sqrt' from SINGLE_MATH with the above `Positive_infinity'
> > > I
> > > get the error "Precondition violated." from SINGLE_MATH. Does this seem
> > > correct?
> > > Regards
> > > Chris Saunders
> >
>