double a = 1e-10;?

C

Camellia

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.
 
C

Chris Dollin

Camellia said:
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.)
 
I

Ian Malone

Camellia said:
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;
}
 
C

Camellia

Have you tried?

#include <stdio.h>

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

}

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:)
 
C

Chris Dollin

Chris Dollin wrote:

Complete rubbish, owing to his inability to see the second line
of the floating-constant syntax.
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 ...
 
R

Richard Bos

Camellia said:
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
 
C

CBFalconer

Camellia said:
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
 
T

Thad Smith

<OT>I encourage Camella to rephrase as "why did ... complain" to get a
complete English sentence. ;-)
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.
 
K

Keith Thompson

Camellia said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top