|
-
May 23rd, 2007, 10:03 PM
#16
-
May 24th, 2007, 02:15 AM
#17
Re: atof error
 Originally Posted by sandodo
Thanks! I searched, but didnot find the answer. Maybe not searching enough. 
1/3 cannot be represented by a decimal number, because 3 is not a divisor of 10.
Similarly, 1/5 cannot be represented by a binary float, because 5 is not a divisor of 2.
Numbers that can be represented by binary floats are sums of powers of two.
It's easy to see that these numbers can be expressed with this form:
integer*2**i where i is a negative or positive integer.
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
-
May 24th, 2007, 04:18 AM
#18
Re: atof error
Thanks Paul McKenzie for the helpful link.
 Originally Posted by SuperKoko
1/3 cannot be represented by a decimal number, because 3 is not a divisor of 10.
Similarly, 1/5 cannot be represented by a binary float, because 5 is not a divisor of 2.
Numbers that can be represented by binary floats are sums of powers of two.
It's easy to see that these numbers can be expressed with this form:
integer*2**i where i is a negative or positive integer.
Thanks. the example of 1/3 cannot be represent by decimal number is very good.
However for , cannot understand......
-
May 24th, 2007, 04:40 AM
#19
Re: atof error
 Originally Posted by sandodo
However for , cannot understand...... 
Basically, this means that the only decimal fractions that can be represented exactly in binary are sums of powers (negative or positive) of 2.
For example:
0.5 can be represented exactly in binary, since:
0.5 = 1/2 = 1 * 2^(-1) (where "^" means "to the power of"). The "**" that Superkoko mentioned is the same as "to the power or".
Similarly, 3/16 can be represented in binary exactly since:
3/16 = 3/(2*8) = 3/(2^(-3)).
So basically if the denominator is 1, 2, 4, 8, 16, 32, 64, etc. the number can be represented in binary exactly.
Regards,
Paul McKenzie
-
May 24th, 2007, 04:41 AM
#20
Re: atof error
The ** is for "to-the-power". +ve as well as -ve.
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
-
May 24th, 2007, 06:23 AM
#21
Re: atof error
 Originally Posted by exterminator
The ** is for "to-the-power". +ve as well as -ve.
Right.
Good thing that you mention it, since it wasn't obvious.
I used the ** operator, in order to avoid confusion with the C xor operator ^.
But, I probably caused confusion with this least used convention.
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
-
May 24th, 2007, 10:36 PM
#22
Re: atof error
Thanks a lot to all of you. You guys are great.
All my best!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|