Results 1 to 3 of 3

Thread: [RESOLVED] "Single" for single precision floating point number

  1. #1

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: "Single" for single precision floating point number

    Thanks,

    I got the same kind of explanation there in MSDN.

    Quote 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
  •  



Click Here to Expand Forum to Full Width