From owner-freebsd-questions Mon Feb 7 17:38:45 2000 Delivered-To: freebsd-questions@freebsd.org Received: from monsoon.mail.pipex.net (monsoon.mail.pipex.net [158.43.128.69]) by builder.freebsd.org (Postfix) with SMTP id EDBC940F2 for ; Mon, 7 Feb 2000 17:38:37 -0800 (PST) Received: (qmail 25557 invoked from network); 8 Feb 2000 01:39:24 -0000 Received: from useran57.uk.uudial.com (HELO marder-1.) (62.188.135.74) by smtp.dial.pipex.com with SMTP; 8 Feb 2000 01:39:24 -0000 Received: (from mark@localhost) by marder-1. (8.9.3/8.9.3) id BAA04839; Tue, 8 Feb 2000 01:39:00 GMT (envelope-from mark) Date: Tue, 8 Feb 2000 01:39:00 +0000 From: Mark Ovens To: Fabio Miranda Cc: freebsd-questions@freebsd.org Subject: Re: Floating point expection - Core dumped Message-ID: <20000208013900.E3126@marder-1> References: <20000207234427.14329.qmail@web124.yahoomail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0pre2i In-Reply-To: <20000207234427.14329.qmail@web124.yahoomail.com> Organization: Total lack of Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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