Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Feb 2000 01:39:00 +0000
From:      Mark Ovens <mark@ukug.uk.freebsd.org>
To:        Fabio Miranda <fmirand@yahoo.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Floating point expection - Core dumped
Message-ID:  <20000208013900.E3126@marder-1>
In-Reply-To: <20000207234427.14329.qmail@web124.yahoomail.com>
References:  <20000207234427.14329.qmail@web124.yahoomail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Feb 07, 2000 at 03:44:27PM -0800, Fabio Miranda wrote:
> hi, the following ask for x and n values and realize
> this funcion :
> 
> P = (3x+2)/n! * E(n,i=1) (x^(n+1-i)) / (n+1-i)!))^2
> 
> I compile it $gcc -o e1 e1.c -lm
> I compile and works fine on NetBSD and solaris.
> On  FreeBSD compiles good, but when n and x are >= 10,
> it says "Floating point expection - core dumped"
> 
> thanks for help, code below:

[snip]

> 
> /* Numerador */
> b1 =  pow(x, t);
  ^^^^^^^^^^^^^^^

It crashes here, pow(3) is declared as:

	double pow(double x, double y)

but you declare b1 as int and 10**10 is 10 000 000 000 which is too
big for an int.

Change b1 to a long, or a double and it works:

int x, n, a1, i=1, a2=1, temp=1, b2=1, w=1,    
temp1=1, t, y;
double A, B, P, C, sumt=0, b1;

marder-1:/usr/marko{97}% cc -o e1 -Wall e1.c -lm
e1.c:18: warning: return-type defaults to `int'
e1.c: In function `main':
e1.c:21: warning: unused variable `temp1'
marder-1:/usr/marko{98}% ./e1
Estructura de Lenguajes de Programacion
Laboratorio No. 1
Desarrollado por: Fabio Andres Miranda
Compilado en GNU cc sobre FreeBSD
(Unix)

Use: $ cc -o e1 e1.c -lm
     $ ./e1
----------------------------------------
Por favor, ingrese el valor de x:11
Por favor, ingrese el valor de n:11
 
 P = 1054.6858

marder-1:/usr/marko{100}% 

HTH.

-- 
	Microsoft: Where do you want to go today?
	Linux:     Where do you want to go tomorrow?
	BSD:       Are you guys coming, or what?
			              -Poster at LinuxWorld 2000
________________________________________________________________
      FreeBSD - The Power To Serve http://www.freebsd.org
      My Webpage http://ukug.uk.freebsd.org/~mark/
mailto:mark@ukug.uk.freebsd.org             http://www.radan.com



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000208013900.E3126>