473,395 Members | 1,870 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,395 software developers and data experts.

double a = 1e-10;?

Just a humble question, I tried to assign a real number with exponents
to a variable but obviously I can't do:
double a = 1e-10;
The compiler will in turn complain about the undefined 'e'.

So, how do I suppose to do it?

Thanks in advance.

Feb 2 '07 #1
8 37883
Camellia wrote:
Just a humble question, I tried to assign a real number with exponents
to a variable but obviously I can't do:
double a = 1e-10;
The compiler will in turn complain about the undefined 'e'.
For no terribly good reason I can think of, using an exponent
requires that the number contain a decimal point. So

double a = 1.0e-10;

looks like your sentient being. (Yes, I /know/ the 0 after the .
isn't required by the C lexis.)

--
Chris "electric hedgehog" Dollin
Nit-picking is best done among friends.

Feb 2 '07 #2
Camellia wrote:
Just a humble question, I tried to assign a real number with exponents
to a variable but obviously I can't do:
double a = 1e-10;
The compiler will in turn complain about the undefined 'e'.
Have you tried?

#include <stdio.h>

int main(void) {
double a=1e-1;
printf("%f\n",a);
return 0;
}

--
imalone
Feb 2 '07 #3
On Feb 2, 10:31 pm, Ian Malone <i...@cam.ac.ukwrote:
Camellia wrote:
Just a humble question, I tried to assign a real number with exponents
to a variable but obviously I can't do:
double a = 1e-10;
The compiler will in turn complain about the undefined 'e'.

Have you tried?

#include <stdio.h>

int main(void) {
double a=1e-1;
printf("%f\n",a);
return 0;

}

--
imalone
I tried:
double a=1e-37;
AGAIN and it worked.

But why the compiler complained about the undefined 'e' last time?

Anyway Thank you guys very much for the help:)

Feb 2 '07 #4
Chris Dollin wrote:

Complete rubbish, owing to his inability to see the second line
of the floating-constant syntax.
Camellia wrote:
>Just a humble question, I tried to assign a real number with exponents
to a variable but obviously I can't do:
double a = 1e-10;
The compiler will in turn complain about the undefined 'e'.

For no terribly good reason I can think of, using an exponent
requires that the number contain a decimal point.
I'm wrong. Wrong with a big W. Wrong with /3/ big W's: WWWrong,
WWWrong, WWWrong.

Camellia had best show us their non-working code ...

--
Chris "WWWrong hedgehog. NO BICUIT. WroWngW." Dollin
"People are part of the deign. It's dangerou to forget that." /tar Cop/

Feb 2 '07 #5
"Camellia" <br*********@gmail.comwrote:
I tried:
double a=1e-37;
AGAIN and it worked.

But why the compiler complained about the undefined 'e' last time?
Did you perchance have a space between the 1 and the e?

(And if so, that's your cue to change to a monospaced font for code.)

Richard
Feb 2 '07 #6
Richard Bos wrote:
"Camellia" <br*********@gmail.comwrote:
>>I tried:
double a=1e-37;
AGAIN and it worked.

But why the compiler complained about the undefined 'e' last time?
<OT>I encourage Camella to rephrase as "why did ... complain" to get a
complete English sentence. ;-)
</OT>
>
Did you perchance have a space between the 1 and the e?

(And if so, that's your cue to change to a monospaced font for code.)
It's also a reason to paste actual code here, rather than retyping.

--
Thad
Feb 2 '07 #7
Camellia wrote:
>
Just a humble question, I tried to assign a real number with exponents
to a variable but obviously I can't do:
double a = 1e-10;
The compiler will in turn complain about the undefined 'e'.

So, how do I suppose to do it?
Complain to your compiler supplier. Others have given you
work-arounds. It clearly is correct. See the following from N869:

(6.4.4.2) decimal-floating-constant:
fractional-constant exponent-part-opt
floating-suffix-opt
digit-sequence exponent-part
floating-suffix-opt
.... snip ...

(6.4.4.2) fractional-constant:
digit-sequence-opt . digit-sequence
digit-sequence .

(6.4.4.2) exponent-part:
e sign-opt digit-sequence
E sign-opt digit-sequence

(6.4.4.2) sign: one of
+ -

(6.4.4.2) digit-sequence:
digit
digit-sequence digit

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
Feb 2 '07 #8
"Camellia" <br*********@gmail.comwrites:
Just a humble question, I tried to assign a real number with exponents
to a variable but obviously I can't do:
double a = 1e-10;
The compiler will in turn complain about the undefined 'e'.
The declaration

double a = 1e-10;

is perfectly legal. It's possible, but very unlikely, that your
compiler has a bug that causes it to reject this legal code. It's far
more likely that the code you posted is not the code your compiler
complained about, and that you accidentally fixed the error when you
re-typed the code for posting.

For example, if your real code were:

double a = e-10;

the compiler would complain that "e" is undeclared (unless you happen
to have declared something called "e").

If you're having trouble with your code, you need to post the *exact*
code. Don't re-type it; copy-and-paste it.

A minor point: If you want to post about this again, please use a name
other than "a". Since "a" is also an English word, it makes it
difficult to write about it. "x" would be fine.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 2 '07 #9

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

Similar topics

2
by: Julián Albo | last post by:
Hello. This test: #include <stdio.h> int main () { double a= -1.0e-120; if (a < 0.0)
2
by: Dave | last post by:
Hello all, I would like to solicit suggestions on how to most efficiently accomplish something. I have profiled the project I'm working on and have found that calls to fabs() are taking a very...
3
by: Hans Ginzel | last post by:
Hello, let us consider function int foo(char *name, void *data) { ... printf(name, data); /* Should be *data? */ ... }
22
by: bq | last post by:
Hello, Two questions related to floating point support: What C compilers for the wintel (MS Windows + x86) platform are C99 compliant as far as <math.h> and <tgmath.h> are concerned? What...
11
by: Greenhorn | last post by:
Hi, K&R says that "floating point constants contain a decimal point (123.4) or an exponent (1e-2) or both; their type is double; unless suffixed. The suffixes f or F indicate a float constant; l...
2
by: Rod Brick | last post by:
I'm trying to print a Double in straight decimal form, not exponential. I can't seem to accomplish this. This seems like it should be simple enough. The output I'm looking for is "0.00001", not...
1
by: bsmith1111 | last post by:
I have a program that outputs the following to the screen (through visual c++) 9999999999, which is stored in a double. I would like to keep the number the way it is, but every time I output it...
2
by: =?Utf-8?B?TnV0c2hlbGw=?= | last post by:
Hey I am running into this issue. I have a Serializable Class that has a Double member. I am using XmlSerializer to serilaize this object, If the Double member is large (or very small) ,...
18
by: brekehan | last post by:
I ran across some code that is initializing a double: double x = 1e-5; Does the standard dictate the compiler to interpret that as 0.00001? or is the above representation error prone? ,...
10
by: ratcharit | last post by:
Currently using cosine function in math.h Currently I get: 1 = cos(1e^-7) Is there another way for cos to return value of high accuracy say: 0.999999 = cos(1e^-7)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.