Re: How to handle crashes?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi Jim, you wrote:

> On Mon, Jun 09, 2003 at 03:53:38PM +0200, Juergen Luethje wrote:
>>
>>
>> Hi Jim, you wrote:
>>
>>> On Sat, Jun 07, 2003 at 07:33:52PM +0200, Juergen Luethje wrote:
>>>>
>>>>
>>>> Hi Jim, you wrote:
>>
>> <snip>
>>
>>>>> What should be done, is to do this.
>>>>>
>>>>> global constant
>>>>> divNAN = -inf/inf,
>>>>> powNAN = power(2, inf),
>>>>> tanNAN = --however you get a NAN from tan()
>>>>
>>>> Because of tan(x) = sin(x)/cos(x),
>>>> tan(x) is undefined, if cos(x) = 0 (i.e. for x = .., -PI/2, PI/2, 3*PI/2,
>>>> ..).
>>>> BTW: With Euphoria, 'cos(PI/2)' does *not* return 0.
>>>
>>> Perhaps its cuz the PI constant isnt accurate enough?
>>
>> And also an IEEE double precision floating point number (8 bytes) isn't
>> accurate enough. Even in another language, which provides IEEE
>> *extended* precision floating point numbers (10 bytes), and using a PI
>> constant with 30 digits after the decimal point, I got for cos(PI/2) the
>> result 4.22838847269347E-18, but not 0.

Small correction for the record:
Although that language generally provides IEEE *extended* precision
floating point numbers, in the meantime I realized, that it's cos()
function only returns *double* precision floating point numbers.

> In my fraction lib, I considers implementing "special" values, which would be
> interpreted as common "irrational" constants

Does this mean, that your lib can handle symbols? I mean, for instance,
can your lib cancel an expression such as "PI*7/PI" to get the exact
result "7" directly? That would be cool. smile

> (such as PI, tho apparently PI isn't irrational iirc).

PI *is* irrational, that means it cannot be expressed as a fraction p/q
for any integers p and q.
However, there are rational approximations for PI, of course.
My favourite is the following, which also is easy to memorize:
     355/113 = 3.14159292...
Althogh this "formula" is very simple, it gives a correct value for PI
to 6 decimal places!

<snip>

[Eu function isnan()]

> Interesting. I'll test it out.

Very nice, thank you!

<snip>

>>> At least my way (using -1), it becomes more of a habit.
>>
>> I normally also use -1, if possible.
>
> As do the libc functions. Like (I think) I said, I borrowed this practice
> from C programming in Linux.

AFAIR I borrowed it from Euphoria and/or from you. blink

Unfortunately, Euphoria is somewhat inconsistent in this regard.
The following text is from the Euphoria 2.3 docs:

* "i1 = define_c_func(a, s1, s2, i2)
  -1 will be returned if the function can't be found."
* "i1 = define_c_proc(a, s1, s2)
  -1 will be returned if the function can't be found."
* "x = dir(st)
  If there is no file or directory with the name st then -1 is
  returned."
* "i = get_key()
  Return -1 if no key was pressed."
* "x1 = get_mouse()
  Return -1 if there has not been a mouse event since the last
  time get_mouse() was called."
* "i = getc(fn)
  -1 is returned at end of file."
* "x = getenv(s)
  If the variable is undefined return -1."
* "x = gets(fn)
  -1 is returned on end of file."
* "fn = open(st1, st2)
  -1 is returned if the open fails."
* "i = routine_id(st)
  -1 is returned if the named routine can't be found."
* "i1 = system_exec(st, i2)
  If it is not possible to run the program, system_exec() will
  return -1."

  ---=-------------=---

* "a = allocate(i)
  Return 0 if the memory can't be allocated."
* "i2 = allocate_low(i1)
  Return 0 if the memory can't be allocated."
* "a = allocate_string(s)
  If there is not enough memory available, 0 will be returned."
* "a = open_dll(st)
  0 will be returned if the .dll (or .so) can't be found."


IMHO it would be more elegant, if
   allocate()
   allocate_low()
   allocate_string()
   open_dll()

also would return -1, rather than 0.


Best regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  |  while not asleep do
 \ /  against HTML in       |     sheep += 1
  X   e-mail and news,      |  end while
 / \  and unneeded MIME     |

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu