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


Groups > comp.lang.c > #54779

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

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: C program. run time abend, range fault.
Date 2014-12-16 23:44 +0000
Organization A noiseless patient Spider
Message-ID <87h9wv40st.fsf@bsb.me.uk> (permalink)
References <3636bf65-fa27-43a6-b54f-45477b249b5d@googlegroups.com> <cfag0nF9r44U1@mid.uni-berlin.de> <079d80e9-04b3-4ea4-958a-72033e2c46e0@googlegroups.com>

Show all headers | View raw


Shiva <subramanian.klu@gmail.com> writes:
<snip>
> I've had corrected these and added the variables as globals. And I've
> had also passed the returns from functions into variables. Below is
> the corrected code (from memory) point me if it is wrong, but I got
> the functionality of fortran code replicated into the C code, of which
> I'm sure.
>
> Can you please answer the original question now that I got the right
> code? 

Your code is very odd what makes it hard to believe that you really
wanted to write what you've posted.  What's more, you code is not
syntactically correct because you are posting some approximation of the
real code.  Please, post the real code.  There may be other errors that
are affecting what you see, and I may be commenting on errors that are
not in the real code...

> long long int pA, pB, pC, pD, pF, pN;
> double z, A;
>
> long long int funcA (long long int, long long int, long long int, long
> long int, long long int, long long int)
>
>     { 
>     ... Initialisation... 
>
>     z = funcB (A, pF, pN, pD, pC, pB, pA, z); 
>
>     ...initialisations value assigning to other variables...A 
>
>
>     z = funcB (A, pF, pN, pD, pC, pB, pA, z); 
>
>     do 
>     { 
>
>      A = funcC (A, pF, pN, pD, pC, pB, pA, v, w, x, y, z); 
>
>      count = count + 1; 
>
>      } while (((z >= 0.0001) || (z <= 0.0001)) && count < limit); 

This is very odd.  Do you know what a NaN is?  Only of z is a NaN will
the test on z be anything but true so it's probably pointless.  What's
more, the body of the loop can't change z so testing it in the loop
condition is just bizarre.  You don't show or say how count is
initialised, but if it starts at something sensible (zero, say) then, in
the absence of NaNs, this loop terminates when count == limit.

>      if ( count = limit) 

This is an assignment and sets, rather than tests, count.  Did you mean
count == limit?

>      A = -1; 
>
>     else 
>     { 
>      ... Some more math.. 
>      } 
>      return A; 
>      } 
>
>
>      double funcB (double A, int pF, int pN, int pD, double pC, double pB, double pA, double z) 
>
>      { 

This function does not use z so it should not be a parameter.  Why are
the globals declared long long int and these parameters int?  Is that
correct?  Is there a prototype for this function in scope in the loop
above?  If not, you have another problem.  (Just ask if you don't know
what I mean by this.)

>      z = (pow (A, pF) * (A - 1)) / (1 - (pow (A, -pN))); 
>
>      z = pB / z; 
>      z = z - pA - (pC / pow (A, pD)); 
>
>     return (z);
>
>      } 
<snip>
> If you see the error that I have listed above - it says that the range
> fault occurs in funcB (I have debugged to the point that it is
> actually line one of funcB) It is trying to calculate the value for
> (1/10 ^ 72) or something like that. Can get you the exact value if
> you'd like. That's where it gives the range fault.

This is the least interesting fault in the program!  A range error just
means that the pow function overflows or underflow and that just means
the some out-of-range values get passed.  The solution is not to pass
values that cause the out-of-range result or to test that this has
happened.

> So as I mentioned it happens in line 1 of funcB when it is called by
> funcC, which is called by funcA which is called by some other COBOL
> program.

Please post the real code and an example of a call (i.e. what values get
passed to funcA).

> Just want to catch this run time error. Not sure what you mean by
> libraries. 

The general technique is to:

(a) include errno.h
(b) set errno = 0 before the function call in question (here, pow)
(c) test for errno == ERANGE after the call.

> I use STDIO.H, STDLIB.H and MATH.H nothing else. And the compiler I
> use is C89 version for Tandem HP NS product.

It's stdio.h, stdlib.h and math.h (and now you need errno.h) but that
compiler is an antique.  That only matters because C89 does not have
long long int so you may be using some odd compiler extension.

-- 
Ben.

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