views:

555

answers:

5

Hi there ;-)

I've written a small function in C, which almost do the same work as standart function `fcvt'. As you may know, this function takes a float/double and make a string, representing this number in ANSI characters. Everything works ;-)

For example, for number 1.33334, my function gives me string: "133334" and set up special integer variable `decimal_part', in this example will be 1, which means in decimal part only 1 symbol, everything else is a fraction.

Now I'm curious about what to do standart C function `printf'. It can take %a or %e as format string. Let me cite for %e (link junked):

"double" argument is output in scientific notation

[-]m.nnnnnne+xx

... The exponent always contains two digits.

It said: "The exponent always contains two digits". But what is an Exponent? This is the main question. And also, how to get this 'exponent' from my function above or from `fcvt'.

I'm not good at Math at all. So, don't poke me, if I'm asking dumb question ;-)

Thanks for patience.

A: 

The exponent is the power 10 is raised to then multiplied by the base.

SI is explained at wikipeida. http://en.wikipedia.org/wiki/Scientific_notation

m.nnnnnne+xx is logically equal to m.nnnnnn * 10 ^ +xx

Daniel A. White
A: 

400 = 4 * 10 ^ 2

2 is the exponent.

CannibalSmith
A: 

In scientific notation, the exponent is the ten to the XX power, so 1234.5678 can be represented as 1.2345678E03 where the normalized form is multiplied by 10^3 to get the "real" answer.

Steve Moyer
+1  A: 

The notation might be better explained if we expand the e:

[-]m.nnnnnn * (10^xx)

So you have one digit of m (from 0 to 9, but it will only ever be 0 if the entire value is 0), and several digits of n. I guess it might be best to show with examples:

1 = 1.0000 * 10^0 = 1e0
10 = 1.0000 * 10^1 = 1e1
10000 = 1.0000 * 10^4 = 1e4
0.1 = 1.0000 * 10^-1 = 1e-1

1,419 = 1.419 * 10^3 = 1.419e3
0.00000123 = 1.23 * 10^-5 = 1.23e-5

You can look up scientific notation off Google, but it is useful for expressing very large or small numbers like 1232100000000000000 would be 1.2321e24 (I didn't actually count, exponent may be inaccurate).

In C, I think you can actually extract the exponent from the top 12 bits (the first being the sign which you will have to ignore). See: IEEE758-1985 Floating Point

CookieOfFortune
A: 

If you write a number in scientific notation then the exponent is part of that notation.

You can see a full description here http://en.wikipedia.org/wiki/Scientific_notation, but basically its just another way to write a number, typically used for very large or very small numbers.

Say you have the number 300, that is equal to 3 * 100, or 3 * 10^2 in scientific notation.

If you use %e it will be printed as 3.0e+02

Andre Miller