From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: linux prg <linux-c-programming@vger.kernel.org>
Subject: Re: Floating point exception
Date: Sat, 11 Sep 2004 16:58:15 +0200 [thread overview]
Message-ID: <20040911145815.GP19967@lug-owl.de> (raw)
In-Reply-To: <20040911113913.86435.qmail@web52904.mail.yahoo.com>
[-- Attachment #1: Type: text/plain, Size: 1820 bytes --]
On Sat, 2004-09-11 12:39:13 +0100, Ankit Jain <ankitjain1580@yahoo.com>
wrote in message <20040911113913.86435.qmail@web52904.mail.yahoo.com>:
> #include<stdlib.h>
> #include<string.h>
> #include<complex.h>
> #include<errno.h>
> #include<time.h>
> #include<stdio.h>
> #define NX 4
> #define NY 4
> #define N 2*NX*NY //N is the size of 2 D DFT
Braces missing
> #include <math.h>
You'd first finish all includes, then add your own defines.
> #define num 2
> #define SWAP(a,b) tempr=(a);(a)=(b);(b)=tempr
This may cause subtle errors. Consider
if (something)
SWAP (x, y);
Only the part "tempr=(a);" would be executed conditionally, what is not
exactly what you intended. I suggest using:
#define SWAP(a,b) \
do { \
tempr = (a); \
(a) = (b); \
(b) = tempr; \
} while (0)
> void fft(float data[], unsigned long nn[], int ndim,
> int isign)
> {
> int idim;
> unsigned long
> i1,i2,i3,i2rev,i3rev,ip1,ip2,ip3,ifp1,ifp2;
> unsigned long ibit,k1,k2,n,nprev,nrem,ntot;
> float tempi,tempr;
> double theta,wi,wpi,wpr,wr,wtemp; //Double precision
> for trigonometric recur-rences.
> for (ntot=1,idim=1;idim<=ndim;idim++) //Compute
> total number of complex val-ues.
> ntot *= nn[idim];
> nprev=1;
>
> for (idim=ndim;idim>=1;idim--)
> { // Main loop over the dimensions.
> n=nn[idim];
> nrem=ntot/(n*nprev);
In your example code, n may become zero, so you devide by zero, which
isn't legal.
MfG, JBG
--
Jan-Benedict Glaw jbglaw@lug-owl.de . +49-172-7608481 _ O _
"Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg _ _ O
fuer einen Freien Staat voll Freier Bürger" | im Internet! | im Irak! O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
prev parent reply other threads:[~2004-09-11 14:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-11 11:39 Floating point exception Ankit Jain
2004-09-11 14:58 ` Jan-Benedict Glaw [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040911145815.GP19967@lug-owl.de \
--to=jbglaw@lug-owl.de \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).