|
-
Jun 17th, 2007, 10:14 PM
#1
Thread Starter
PowerPoster
[RESOLVED] "Single" for single precision floating point number
As the title, ‘Single’ holds a single decimal number? Or the result holds a single decimal value? Or anything else?
Ok, just look at the following code fragment.
Code:
Single p = 225.2F;
Single q = 12.54F;
Single r = p / q;
Console.WriteLine(r);
Output is 17.95853, and I’ve no idea what’s happened there. Where the single precision is?
Check on MSDN and fail. Please help me. How can I use it?
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
-
Jun 17th, 2007, 10:24 PM
#2
Re: "Single" for single precision floating point number
I have to say, you mustn't have looked very far. This is from the MSDN help topic for the Single structure:
The Single value type represents a single-precision 32-bit number with values ranging from negative 3.402823e38 to positive 3.402823e38, as well as positive or negative zero, PositiveInfinity, NegativeInfinity, and not a number (NaN).
Single complies with the IEC 60559:1989 (IEEE 754) standard for binary floating-point arithmetic.
as is this:
Remember that a floating-point number can only approximate a decimal number, and that the precision of a floating-point number determines how accurately that number approximates a decimal number. By default, a Single value contains only 7 decimal digits of precision, although a maximum of 9 digits is maintained internally.
Here are the equivalent quotes from the MSDN help topic for the Double structure:
The Double value type represents a double-precision 64-bit number with values ranging from negative 1.79769313486232e308 to positive 1.79769313486232e308, as well as positive or negative zero, PositiveInfinity, NegativeInfinity, and Not-a-Number (NaN).
Double complies with the IEC 60559:1989 (IEEE 754) standard for binary floating-point arithmetic.
Remember that a floating-point number can only approximate a decimal number, and that the precision of a floating-point number determines how accurately that number approximates a decimal number. By default, a Double value contains 15 decimal digits of precision, although a maximum of 17 digits is maintained internally.
-
Jun 17th, 2007, 10:44 PM
#3
Thread Starter
PowerPoster
Re: "Single" for single precision floating point number
Thanks,
I got the same kind of explanation there in MSDN.
 Originally Posted by jmcilhinney
Remember that a floating-point number can only approximate a decimal number, and that the precision of a floating-point number determines how accurately that number approximates a decimal number. By default, a Single value contains only 7 decimal digits of precision, although a maximum of 9 digits is maintained internally.
As this says, single just approximating the 7th decimal point in floating-point numbers and the 15th decimal point in double type number.
Am I correct.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
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
|