473,320 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

getting -0.0 output ?

what is it and why does it occur in programs performing floating point
calculations ? Is it harmful? if yes, then what are the possible
solutions. Btw here was my input to the program:

input
*******
Enter theta, phi, r
0
0
0
output
********
-0.000000 0.000000 -1.000000

#include <stdio.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159
#endif
#define deg2radian(x) ((M_PI/180) * (x))

int main(void)
{
double theta, phi;
double thetahat[3], phihat[3];
double r;
double rhat[3];

printf("Enter theta, phi, r\n");
scanf("%lf %lf %lf", &theta, &phi, &r);

theta = deg2radian(theta);
phi = deg2radian(phi);

thetahat[0] = -sin(theta);
thetahat[1] = cos(theta);
thetahat[2] = 0;

phihat[0] = cos(theta) * cos(phi);
phihat[1] = sin(theta) * cos(phi);
phihat[2] = -sin(phi);

rhat[0] = thetahat[1] * phihat[2] - thetahat[2] * phihat[1];
rhat[1] = thetahat[2] * phihat[0] - thetahat[0] * phihat[2];
rhat[2] = thetahat[0] * phihat[1] - thetahat[1] * phihat[0];

printf("%f %f %f\n ", rhat[0], rhat[1] , rhat[2]);
return 0;
}
Jun 27 '08 #1
4 1255
pereges wrote:
What is -0.0?
The following document might be of interest.

http://docs.sun.com/source/806-3568/ncg_goldberg.html
Jun 27 '08 #2
pereges <Br*****@gmail.comwrote:
>
what is it [-0.00000]?
It's a very small negative number (e.g., -0.000000000001).

-- Larry Jones

I kind of resent the manufacturer's implicit assumption
that this would amuse me. -- Calvin
Jun 27 '08 #3
In article <8j************@jones.homeip.net>,
<la************@siemens.comwrote:
>what is it [-0.00000]?
It's a feature of IEEE floating point, which is more-or-less universal
now, but not required by the C standard.
>It's a very small negative number (e.g., -0.000000000001).
This is sometimes true, in the same sense that +0.0000 is sometimes a
very small positive number, because of finite precision. But positive
and negative zero are also used to represent a zero that results from
operations that can be considered limits approached from above or below.
For example, 1/inf is 0, but 1/-inf is -0. Use of -0 allows functions
with branch cuts in the complex plane to be more consistently defined.

-- Richard
--
In the selection of the two characters immediately succeeding the numeral 9,
consideration shall be given to their replacement by the graphics 10 and 11 to
facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)
Jun 27 '08 #4
On Jun 11, 7:30*am, pereges <Brol...@gmail.comwrote:
what is it and why does it occur in programs performing floating point
calculations *? Is it harmful? if yes, then what are the possible
solutions. Btw here was my input to the program:

input
*******
Enter theta, phi, r
0
0
0
output
********
-0.000000 0.000000 -1.000000

#include <stdio.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159
#endif
#define deg2radian(x) ((M_PI/180) * (x))

int main(void)
{
* double theta, phi;
* double thetahat[3], phihat[3];
* double r;
* double rhat[3];

* printf("Enter theta, phi, r\n");
* scanf("%lf %lf %lf", &theta, &phi, &r);

* theta = deg2radian(theta);
* phi = deg2radian(phi);

* thetahat[0] = -sin(theta);
* thetahat[1] = cos(theta);
* thetahat[2] = 0;

* phihat[0] = cos(theta) * cos(phi);
* phihat[1] = sin(theta) * cos(phi);
* phihat[2] = -sin(phi);

* rhat[0] = thetahat[1] * phihat[2] - thetahat[2] * phihat[1];
* rhat[1] = thetahat[2] * phihat[0] - thetahat[0] * phihat[2];
* rhat[2] = thetahat[0] * phihat[1] - thetahat[1] * phihat[0];

* printf("%f %f %f\n ", rhat[0], rhat[1] , rhat[2]);

* return 0;
}
#include <stdio.h>
#include <math.h>
#include <float.h>
#ifndef M_PI
#define M_PI 3.141592653589793238462643383279502884197169399375 1
#endif
#define deg2radian(x) ((M_PI/180) * (x))
int main(void)
{
double theta,
phi;
double thetahat[3],
phihat[3];
double r;
double rhat[3];
int converted;

oops:
printf("Enter theta, phi, r\n");
converted = scanf("%lf %lf %lf", &theta, &phi, &r);
if (converted != 3) goto oops;

theta = deg2radian(theta);
phi = deg2radian(phi);
thetahat[0] = -sin(theta);
thetahat[1] = cos(theta);
thetahat[2] = 0;
phihat[0] = cos(theta) * cos(phi);
phihat[1] = sin(theta) * cos(phi);
phihat[2] = -sin(phi);
rhat[0] = thetahat[1] * phihat[2] - thetahat[2] * phihat[1];
rhat[1] = thetahat[2] * phihat[0] - thetahat[0] * phihat[2];
rhat[2] = thetahat[0] * phihat[1] - thetahat[1] * phihat[0];

printf("%*.*g %*.*g %*.*g\n ",
DBL_DIG + 3, DBL_DIG, rhat[0],
DBL_DIG + 3, DBL_DIG, rhat[1],
DBL_DIG + 3, DBL_DIG, rhat[2]);
return 0;
}
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Philip Ronan | last post by:
OK, here's my 2p worth: === Q. Why am I getting the error message 'Headers already sent'? A. PHP produces this error message when you try to set a header for a web page after you have already...
3
by: sp | last post by:
hai i have got 1. an xml file 2. an xsl file and my xsl file filters the xml based on attribute value and the output i receive is in the ordinary format
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
1
by: Alec MacLean | last post by:
Hi, Outline of problem: I've built a set of user controls that are used to output questions for a survey and gather the responses using simple radio buttons. I'm adding an optional textbox...
2
cassbiz
by: cassbiz | last post by:
I am using strtotime and I have read up on some examples and am getting the wrong output, it jumps by several days instead of one day at a time. Ultimately what I am trying to accomplish is to set...
1
by: John Bailo | last post by:
This is a my solution to getting an Output parameter from a SqlDataSource. I have seen a few scant articles but none of them take it all the way to a solution. Hopefully this will help some...
10
by: hpbrothers | last post by:
#include<iostream.h> #include<conio.h> void main() { int a,b,i,j,k=0,fg=0; for(i=0;i<5;i++) { cout<<"enter no."; cin>>a;}
2
by: hpbrothers | last post by:
#include<iostream.h> void main() { char mstr; char cstr; int c=1,k=0,i,j; cout<<"enter main string"; cin.getline(mstr,100); for(i=0;mstr!='\0';i++) {
2
by: preeti13 | last post by:
Hi guys i am here with my another probelm please help me.trying insert the value into the data base but getting the null value error .I am getting thsi error Cannot insert the value NULL into...
3
by: Rainy | last post by:
Hello! I'm having some trouble with pyserial package, I'm sending commands and reading responses from a custom pcb, and sometimes I get a proper response, at other times I get nothing, and...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.