1. Absolute

Lucius,  thanks for the apology. It's fine if you're having a bad time to
vent some anger - I've been observing this list long enough to know you
don't usually get that cranky.

Please understand that I am completely uneducated (only to Year 12 in
Australia - which is high school in the US) and only program to save time
with my stock market analysis, and a few other small projects. I say this in
advance because the following questions may seem ignorant.

If x is the largest possible atom,  what happens when your program calls
x+1?
Or 2x?  Or any other equation that will make x bigger than x already is?
Obviously the program will crash. Are there methods commonly used to avoid
this happening if it is possibly likely (e.g if x>too_big then
approximate(x) and inform) or do we just hope it doesn't happen? How many
other algorithms that we use every day might possibly crash?

I, for one, will only be using the absolute() function you suggested from
now on. I'm interested to know if you could suggest any more.

Kind Regards,
Aidan

new topic     » topic index » view message » categorize

2. Re: Absolute

Aidan Bindoff wrote:

> If x is the largest possible atom,  what happens when your program calls
> x+1?

I'll chip in here, this is covered in the Euphoria Referance Manual.  I quote:

 Computing a result that is too big (i.e. outside of -1e300 to +1e300) will
result in one of the special atoms
 +infinity or -infinity. These appear as inf or -inf when you print them out.
It is also possible to generate nan or -nan. "nan" means "not a number", i.e.
an undefined value (such as inf divided by inf). These values are defined in
the IEEE floating-point standard. If you see one of these special values in
your output, it usually indicates an error in your program logic, although
generating inf as an intermediate result may be acceptable in some cases. For
instance, 1/inf is 0, which may be the "right" answer for your algorithm.

-Version 2.1 Windows Ref. Manual. file:///C|/EUPHORIA/HTML/refman_2.htm#1 for
default installation.

Personally, I would agree with Robert if he were to say this is good enough
for most non-critical purposes.

--
Nic (RedWord)Smith

new topic     » goto parent     » topic index » view message » categorize

3. Re: Absolute

----- Original Message -----
From: "Aidan Bindoff" <abindoff at one.net.au>
To: "Euphoria Programming for MS-DOS" <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Saturday, June 10, 2000 10:16 PM
Subject: Absolute


  <SNIP>
>
> If x is the largest possible atom,  what happens when your program calls
> x+1?

if x is the largest possible atom then x must be a float64.
This means that x+1 will yield +inf.  Same rule applies if x is the smallest
possible atom and you tried x-1.  You get -inf.  The program doesn't crash
when it comes to atoms going out of range but it will crash when integers go
out of range.

> Or 2x?  Or any other equation that will make x bigger than x already is?
> Obviously the program will crash. Are there methods commonly used to avoid
> this happening if it is possibly likely (e.g if x>too_big then
> approximate(x) and inform) or do we just hope it doesn't happen?

Euphoria doesn't have error trapping.  For those that don't know what that
is.
Error trapping is when an error occurs and the program is written to try and
handle the error as gracefully as possible.
Example:
  Dave: Add 1 to x
  Hal: I'm sorry, I can't allow you to do that, Dave.

Some computer languages allow error trapping.  When an error occurs during
error trapping the program is sent to a specific set of code that the
programmer has defined to try and handle the error.  When the error occurs a
variable is setup that is a number detailing what the error was that
occurred.
The programmer can define code to handle errors that he knows can occur in
order to keep the program running as long as possible.  The programmer could
also have some emergency shutdown code written in this area.  If an error
was
detected he would have the chance to save and close all files before
crashing
they program.

> How many
> other algorithms that we use every day might possibly crash?

No telling, I just deal with them one at a time as I see them.

>
> I, for one, will only be using the absolute() function you suggested from
> now on. I'm interested to know if you could suggest any more.

Nothing currently comes to mind.

>
> Kind Regards,
> Aidan
>

        Lucius L. Hilley III
        lhilley at cdc.net
+--------------+--------------+
| ICQ: 9638898 | AIM: LLHIII  |
+--------------+--------------+
| http://www.cdc.net/~lhilley |
+-----------------------------+

new topic     » goto parent     » topic index » view message » categorize

4. Re: Absolute

On 11 Jun 2000, at 2:36, Lucius L. Hilley III wrote:


> > Or 2x?  Or any other equation that will make x bigger than x already
> > is? Obviously the program will crash. Are there methods commonly
> > used to avoid this happening if it is possibly likely (e.g if
> > x>too_big then approximate(x) and inform) or do we just hope it
> > doesn't happen?
>
> Euphoria doesn't have error trapping.  For those that don't know what
> that is. Error trapping is when an error occurs and the program is
> written to try and handle the error as gracefully as possible.
> Example:
>   Dave: Add 1 to x
>   Hal: I'm sorry, I can't allow you to do that, Dave.

Which, in some models, would be an error on your part, Hal.

largest_atom + 1 = +inf
+inf + 1 = -inf
-inf + 1 = -inf + 1

Kat

new topic     » goto parent     » topic index » view message » categorize

5. Re: Absolute

On Sun, 11 Jun 2000 12:16:50 +1000, Aidan Bindoff <abindoff at ONE.NET.AU>
wrote:

>I, for one, will only be using the absolute() function [Lucius] suggested
>from now on. I'm interested to know if you could suggest any more.

The 'sequence-magic' abs() function is:

function abs(object x)
    -- The bit in the outer brackets is normally in the function "sgn()"
    return x * ( (x>0)-(x<0) )
end function

This works for anything you want to throw at it. The downside is that it's
3-4 times slower than the atom-only version when you use it on atoms.

Carl - Sequence magic intermediate blink

--
.sig still missing

new topic     » goto parent     » topic index » view message » categorize

6. Re: Absolute

On Sun, 11 Jun 2000 12:16:50 +1000, Aidan Bindoff <abindoff at ONE.NET.AU>
wrote:

>If x is the largest possible atom,  what happens when your program calls
>x+1?

I think Euphoria will give you "inf"

new topic     » goto parent     » topic index » view message » categorize

7. Re: Absolute

On Mon, 12 Jun 2000 09:39:32 -0400, Carl R. White <cyrek at BIGFOOT.COM> wrote:


>The 'sequence-magic' abs() function is:
>
>function abs(object x)
>    -- The bit in the outer brackets is normally in the function "sgn()"
>    return x * ( (x>0)-(x<0) )
>end function
Or you could use something I saw a while ago...

function abs(atom x)
    return sqrt(x * x)
end function

I always use it, and it's served me well

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu