Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #55021

Re: C program. run time abend, range fault.

From jt@toerring.de (Jens Thoms Toerring)
Newsgroups comp.lang.c
Subject Re: C program. run time abend, range fault.
Date 2014-12-19 00:18 +0000
Organization Freie Universitaet Berlin
Message-ID <cfh969F4bg7U1@mid.uni-berlin.de> (permalink)
References (2 earlier) <m6q1m6$jh6$1@speranza.aioe.org> <cfc030Fn3o1U1@mid.uni-berlin.de> <e3eb318e-355d-411b-8215-f2f022485b08@googlegroups.com> <cn049alo4s068v3r5pntdbp9a27bliogd0@4ax.com> <f356152d-b545-4329-a765-68ea430cd83a@googlegroups.com>

Show all headers | View raw


Shiva <subramanian.klu@gmail.com> wrote:

<working code snipped;-)>

Sorry to hear about your rather atrocious sounding working
conditions! Sounds like having a fist fight with both arms
tied to your back;-) So no appologies required for any pro-
blems with the code you post.

While your program now compiles, it doesn't behave for me as
you describe it. And Barry already pointed out that it can't
work properly, even with your "good" inputs. Thus I suspect
that there's still are some deviations from what you used in
your own tests. But the problem you want to solve, as far as
I understand, is not really about the code and it's behaviour
and results, but just how to keep the program from crashing.

To be honest, I don't know. But let me mention a few points
anyway that might help point you in the right direction (my
explanation might be a bit flawed, but I hope that others
with more experience in these matters will chime in and
correct my mistakes):

If the pow() function is called this invokes some function
in the math library. If you have some kind of "floating point
unit" (FPU) on your machine (nowadays part of the CPU, in the
olden days often an additional chip) the math library will send
the arguments to the FPU and instruct it to do the required
calculations.

Now, if the FPU notices that the arguments are unsuitable
or the result would over- or underflow what can be repre-
sented by a floating point number it raises some kind of
"exceptition" (there can be different types for different
error conditions).

The math library now can either "catch" that exception or
pass it on to the caller. If it's set up to catch these
exceptions it will return some kind of result (that may
include 'Inf' or 'NaN', 0, HUGE_VAL etc.) and set 'errno'
appropriately. The caller then can check the return value
and 'errno' to detect possible problems.

If the math library isn't set up to "catch" the exception
the caller may try to do that itself. If he doesn't it may
result in the program aborting. That seems to be what you
are experiencing.

If this is what happens you have, as far as I can see at
the moment, three possibilities:

a) Ensure that the math library catches the errors and
   then deal with cases where 'errno' indicates that
   something went wrong.
b) Catch the floating point exception yourself and deal
   with it in some suitable way (or perhaps set your
   system up to ignore these floating point exceptions -
   but that might result in invalid final results).
c) Check what you're going to pass to pow() and don't call
   it when there's something that might upset the FPU.

The problem is that none of them are simple to implement
and may need some good knowledge about the system and
conpiler you're using, And I never heard of the "Tandem"
system you're working on, what the compiler, the OS or the
CPU architecture migth be.

Possible problems I see at the moment:

a) On all systems I normally have to deal with the math
   library is per default set up to catch floating
   point exceptions. Something must be different on your
   system - perhaps the COBOL program your functions are
   invoked from is doing that. If not, making sure the
   exceptions get caught could involve certain compiler
   flags, arguments to the program or environment vari-
   ables set in a certain way. Otherwise system-specific
   functions may have to be called (which undo the changes
   the COBOL part of the program may have made and perhaps
   also reset stuff back to the previous state when done
   with the C part, so the COBOL part still works as
   before).
b) Catching the floating point exception yourself also
   requires system-specific methods. E.g. on Unix you'd
   have to catch a SIGFPE signal. But this probably will
   be quite different on other operating systems.
c) Vetting the arguments before calling pow() can be quite
   some task - if done 100% correct it might require to write
   some kind of pow() function yourself. But if it's only
   about catching invalid input that might be simpler:
    * catch 0 as the base argument with any negative exponents
    * catch a negative base with anything but odd integer
      exponents
   A conservative ballpark check for over- and underflows
   is also possible but takes some thinking about to get
   right (and to be not too convervative). Let me know if
   you want to go down that road and need help with it. Of
   course this won't speed up the program at all;-(

                     Best regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

C program. run time abend, range fault. Shiva <subramanian.klu@gmail.com> - 2014-12-16 00:47 -0800
  Re: C program. run time abend, range fault. jt@toerring.de (Jens Thoms Toerring) - 2014-12-16 10:31 +0000
    Re: C program. run time abend, range fault. Shiva <subramanian.klu@gmail.com> - 2014-12-16 11:33 -0800
      Re: C program. run time abend, range fault. Barry Schwarz <schwarzb@dqel.com> - 2014-12-16 14:27 -0800
      Re: C program. run time abend, range fault. jt@toerring.de (Jens Thoms Toerring) - 2014-12-16 23:08 +0000
      Re: C program. run time abend, range fault. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-12-16 23:44 +0000
    Re: C program. run time abend, range fault. glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-12-16 19:37 +0000
      Re: C program. run time abend, range fault. jt@toerring.de (Jens Thoms Toerring) - 2014-12-17 00:12 +0000
        Re: C program. run time abend, range fault. Shiva <subramanian.klu@gmail.com> - 2014-12-17 13:05 -0800
          Re: C program. run time abend, range fault. Barry Schwarz <schwarzb@dqel.com> - 2014-12-17 15:06 -0800
            Re: C program. run time abend, range fault. Richard Heathfield <invalid@see.sig.invalid> - 2014-12-17 23:15 +0000
              Re: C program. run time abend, range fault. Keith Thompson <kst-u@mib.org> - 2014-12-17 16:00 -0800
            Re: C program. run time abend, range fault. Keith Thompson <kst-u@mib.org> - 2014-12-17 15:56 -0800
            Re: C program. run time abend, range fault. Shiva <subramanian.klu@gmail.com> - 2014-12-18 12:28 -0800
              Re: C program. run time abend, range fault. Barry Schwarz <schwarzb@dqel.com> - 2014-12-18 14:07 -0800
              Re: C program. run time abend, range fault. Barry Schwarz <schwarzb@dqel.com> - 2014-12-18 14:16 -0800
              Re: C program. run time abend, range fault. jacob navia <jacob@spamsink.net> - 2014-12-19 00:55 +0100
              Re: C program. run time abend, range fault. jt@toerring.de (Jens Thoms Toerring) - 2014-12-19 00:18 +0000
              Re: C program. run time abend, range fault. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-12-19 01:12 +0000
          Re: C program. run time abend, range fault. jt@toerring.de (Jens Thoms Toerring) - 2014-12-18 01:00 +0000
          Re: C program. run time abend, range fault. James Kuyper <jameskuyper@verizon.net> - 2014-12-17 22:29 -0500
            Re: C program. run time abend, range fault. gazelle@shell.xmission.com (Kenny McCormack) - 2014-12-18 09:18 +0000
              Re: C program. run time abend, range fault. Martin Shobe <martin.shobe@yahoo.com> - 2014-12-18 11:10 -0600
                Re: C program. run time abend, range fault. Shiva <subramanian.klu@gmail.com> - 2014-12-18 11:38 -0800
                Re: C program. run time abend, range fault. James Kuyper <jameskuyper@verizon.net> - 2014-12-18 15:24 -0500
                Re: C program. run time abend, range fault. Shiva <subramanian.klu@gmail.com> - 2014-12-18 12:37 -0800
  C program. run time abend, range fault. asetofsymbols@gmail.com - 2014-12-18 22:21 -0800
  Re: C program. run time abend, range fault. Is this the correct solution? jacob navia <jacob@spamsink.net> - 2014-12-19 18:32 +0100
    Re: C program. run time abend, range fault. Is this the correct solution? jacob navia <jacob@spamsink.net> - 2014-12-20 11:34 +0100
      Re: C program. run time abend, range fault. Is this the correct solution? Shiva <subramanian.klu@gmail.com> - 2014-12-31 11:48 -0800
        Re: C program. run time abend, range fault. Is this the correct solution? James Kuyper <jameskuyper@verizon.net> - 2014-12-31 15:49 -0500
        Re: C program. run time abend, range fault. Is this the correct solution? Keith Thompson <kst-u@mib.org> - 2014-12-31 13:07 -0800
          Re: C program. run time abend, range fault. Is this the correct solution? Geoff <geoff@invalid.invalid> - 2014-12-31 13:57 -0800
            Re: C program. run time abend, range fault. Is this the correct solution? Keith Thompson <kst-u@mib.org> - 2014-12-31 16:02 -0800
              Re: C program. run time abend, range fault. Is this the correct solution? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-12-31 22:55 -0800
            Re: C program. run time abend, range fault. Is this the correct solution? raltbos@xs4all.nl (Richard Bos) - 2015-01-05 14:56 +0000
        Re: C program. run time abend, range fault. Is this the correct solution? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-12-31 21:51 +0000
        Re: C program. run time abend, range fault. Is this the correct solution? jacob navia <jacob@spamsink.net> - 2015-01-01 02:51 +0100
          Re: C program. run time abend, range fault. Is this the correct solution? raltbos@xs4all.nl (Richard Bos) - 2015-01-05 15:00 +0000
            Re: C program. run time abend, range fault. Is this the correct solution? Shiva <subramanian.klu@gmail.com> - 2015-01-05 09:45 -0800
              Re: C program. run time abend, range fault. Is this the correct solution? Geoff <geoff@invalid.invalid> - 2015-01-05 11:02 -0800
                Re: C program. run time abend, range fault. Is this the correct solution? Shiva <subramanian.klu@gmail.com> - 2015-01-06 10:33 -0800
                Re: C program. run time abend, range fault. Is this the correct solution? James Kuyper <jameskuyper@verizon.net> - 2015-01-06 14:09 -0500
                Re: C program. run time abend, range fault. Is this the correct solution? Shiva <subramanian.klu@gmail.com> - 2015-01-06 12:32 -0800
                Re: C program. run time abend, range fault. Is this the correct solution? James Kuyper <jameskuyper@verizon.net> - 2015-01-06 15:47 -0500
                Re: C program. run time abend, range fault. Is this the correct solution? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-01-06 23:58 +0000
                Re: C program. run time abend, range fault. Is this the correct solution? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-01-07 04:31 +0000
                Re: C program. run time abend, range fault. Is this the correct solution? Robert Wessel <robertwessel2@yahoo.com> - 2015-01-06 23:36 -0600
                Re: C program. run time abend, range fault. Is this the correct solution? Richard Heathfield <invalid@see.sig.invalid> - 2015-01-07 07:08 +0000
                Re: C program. run time abend, range fault. Is this the correct solution? Shiva <subramanian.klu@gmail.com> - 2015-01-09 13:46 -0800
            Re: C program. run time abend, range fault. Is this the correct solution? Geoff <geoff@invalid.invalid> - 2015-01-05 09:56 -0800
  Re: C program. run time abend, range fault. Geoff <geoff@invalid.invalid> - 2015-01-01 14:38 -0800

csiph-web