Maths & Rounding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daisy

    Maths & Rounding

    Something simple, I'm sure. My code:

    System.Windows. Forms.MessageBo x.Show(((Int32) Math.Ceiling(19 66 /
    100)).ToString( ));

    I'm expecting 20, but getting 19. What am I doing wrong?

    Thanks

    --
    Daisy The Cow
    Now playing: Tomcraft - Loneliness [Radio]


  • Bill Priess

    #2
    Re: Maths & Rounding

    Hi Daisy,

    I got the same results, even though 19.66 should raise to 20. (Maybe a
    bug???) Anyhow, try this:

    System.Windows. Forms.MessageBo x.Show(int.Pars e(Math.Round((d ecimal)1966
    /100).ToString() ).ToString());

    HTH,

    Bill P.

    On Wed, 30 Jul 2003 21:43:46 +0100, Daisy <daisy@nospam.o ops> wrote:
    [color=blue]
    > Something simple, I'm sure. My code:
    >
    > System.Windows. Forms.MessageBo x.Show(((Int32) Math.Ceiling(19 66 /
    > 100)).ToString( ));
    >
    > I'm expecting 20, but getting 19. What am I doing wrong?
    >
    > Thanks
    >[/color]



    --
    Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

    Comment

    • Thomas Tomicek [MVP]

      #3
      Re: Maths &amp; Rounding

      Imho it is right.

      The way things are evaluated is:

      1966 / 100 (int/int) = int

      Math.Ceiling (result from above, being an int)

      Cast to Int32

      Convert to string.

      The trick is that int / int = int is part of how maths works.

      --
      Regards

      Thomas Tomiczek
      THONA Software & Consulting Ltd.
      (Microsoft MVP C#/.NET)

      "Daisy" <daisy@nospam.o ops> wrote in message
      news:bg9bn5$ov8 $1@linux01.dann ytuppeny.com...[color=blue]
      > "Daisy" <daisy@nospam.o ops> wrote in message
      > news:bg9alh$ofr $1@linux01.dann ytuppeny.com...[color=green]
      > > Something simple, I'm sure. My code:
      > >
      > > System.Windows. Forms.MessageBo x.Show(((Int32) Math.Ceiling(19 66 /
      > > 100)).ToString( ));
      > >
      > > I'm expecting 20, but getting 19. What am I doing wrong?[/color]
      >
      > ok, 1966f / 100f works, but this doesn't seem right, I just want a[/color]
      resulting[color=blue]
      > Single from a division of 2 integers... Is this correct??
      > --
      > Daisy The Cow
      > Now playing: Puff Daddy ft Faith Evans - I'll Be Missing You
      >
      >[/color]


      Comment

      • Daisy

        #4
        Re: Maths &amp; Rounding

        "Bill Priess" <no.spam@nospam .com> wrote in message
        news:oprs451jim cimqky@localhos t...[color=blue]
        > Hi Daisy,
        >
        > I got the same results, even though 19.66 should raise to 20. (Maybe a
        > bug???) Anyhow, try this:
        >
        > System.Windows. Forms.MessageBo x.Show(int.Pars e(Math.Round((d ecimal)1966
        > /100).ToString() ).ToString());[/color]

        I shortened it to:

        System.Windows. Forms.MessageBo x.Show(Math.Rou nd((decimal)196 6 /
        100).ToString() );

        And it worked too. I'd just done it by casting both sides to Single, which
        worked. If just one side (assuming cast is done before division?) works,
        that's probably better :o)
        --
        Daisy The Cow
        Now playing: Madonna - Frozen


        Comment

        • Daisy

          #5
          Re: Maths &amp; Rounding

          "Mark" <f1fannz@hotmai l.com> wrote in message
          news:uMf5PqwVDH A.384@TK2MSFTNG P12.phx.gbl...[color=blue]
          > I think you missed the point of integer division
          >
          > an integer divided by an integer to give another integer doesnt round up[/color]
          or[color=blue]
          > down. Integers have no concept of decimal places and do not hold them.
          >
          > Your code to divide 1966 by 100 would result in an integer holding 19, the
          > .66 would just be dropped as there was no memory reserved to hold this[/color]
          part.[color=blue]
          >
          > Hope i shed a bit of light[/color]

          Yeah, I didn't realise it would return an Int. Changing it to

          ((Single)1966 / 100)

          returns a single, as I need :o)
          --
          Daisy The Cow
          Now playing: Nothing


          Comment

          • Thomas Tomicek [MVP]

            #6
            Re: Maths &amp; Rounding

            This is pretty obvious, as I said. All operations are done in the highhest
            precision present.

            int / int = precision int

            float / int = precision float.

            I can only suggest you read the part about maths in the C# language
            specification again.

            --
            Regards

            Thomas Tomiczek
            THONA Software & Consulting Ltd.
            (Microsoft MVP C#/.NET)

            "Daisy" <daisy@nospam.o ops> wrote in message
            news:bgadli$ih$ 1@linux01.danny tuppeny.com...[color=blue]
            > "Mark" <f1fannz@hotmai l.com> wrote in message
            > news:uMf5PqwVDH A.384@TK2MSFTNG P12.phx.gbl...[color=green]
            > > I think you missed the point of integer division
            > >
            > > an integer divided by an integer to give another integer doesnt round up[/color]
            > or[color=green]
            > > down. Integers have no concept of decimal places and do not hold them.
            > >
            > > Your code to divide 1966 by 100 would result in an integer holding 19,[/color][/color]
            the[color=blue][color=green]
            > > .66 would just be dropped as there was no memory reserved to hold this[/color]
            > part.[color=green]
            > >
            > > Hope i shed a bit of light[/color]
            >
            > Yeah, I didn't realise it would return an Int. Changing it to
            >
            > ((Single)1966 / 100)
            >
            > returns a single, as I need :o)
            > --
            > Daisy The Cow
            > Now playing: Nothing
            >
            >[/color]


            Comment

            • Stephen Alpert

              #7
              Re: Maths &amp; Rounding

              On Wed, 30 Jul 2003 21:43:46 +0100, "Daisy" <daisy@nospam.o ops> wrote:
              [color=blue]
              >Something simple, I'm sure. My code:
              >
              >System.Windows .Forms.MessageB ox.Show(((Int32 )Math.Ceiling(1 966 /
              >100)).ToString ());
              >
              >I'm expecting 20, but getting 19. What am I doing wrong?
              >[/color]

              Nobody suggested the obvious. If you want to round, why not
              (year+50)/100

              /steveA


              my email Fgrir_Nycreg@vq k.pbz is encrypted with ROT13 (www.rot13.org)

              Comment

              • Daisy

                #8
                Re: Maths &amp; Rounding

                "Thomas Tomicek [MVP]" <t.tomiczek@tho na-consulting.com> wrote in message
                news:uS8V0azVDH A.2268@TK2MSFTN GP11.phx.gbl...[color=blue]
                > This is pretty obvious, as I said. All operations are done in the highhest
                > precision present.
                >
                > int / int = precision int
                >
                > float / int = precision float.
                >
                > I can only suggest you read the part about maths in the C# language
                > specification again.[/color]

                Yeah thanks, because sarcasm and smart-arséyness is the way you learnt too?

                It's not "pretty obvious" to anybody that's never come across it before. I
                started programming in Perl, PHP and VBScript, so it's not something I've
                noticed. I'm quite suprised to see MVP after your name if this is the
                attitude you usually post with. Whatever happened to the "No such thing as a
                silly question, only a silly answer" way that *most* of the helpful people
                in this group (and indeed this thread) seem to have?

                </rant>
                --
                Daisy The Cow
                Now playing: Nothing


                Comment

                • Daisy

                  #9
                  Re: Maths &amp; Rounding

                  "Thomas Tomicek [MVP]" <t.tomiczek@tho na-consulting.com> wrote in message
                  news:uBATym4VDH A.1180@TK2MSFTN GP11.phx.gbl...[color=blue][color=green]
                  > > Yeah thanks, because sarcasm and smart-arséyness is the way you learnt[/color]
                  > too?
                  >
                  > No, i read it in the language specification for mathematical operations,
                  > instead of trial and error.[/color]

                  I was refering to the language, not what I was posting about ;P


                  [color=blue][color=green]
                  > > It's not "pretty obvious" to anybody that's never come across it before.[/color][/color]
                  I[color=blue]
                  >
                  > Then read the language specification before you start using the language.
                  > This is similar to the C / C++ way of handling things, and it is fully
                  > documented in language specs.[/color]

                  I don't know about you, but I have better things to do than RTFM front to
                  back. I've done enough programming to know how maths works, so it would have
                  been rather a waste of time I could've been coding in. And since there are
                  so many helpful people in groups like this, I decided to use the time
                  coding.

                  And FYI, when I got the wrong result, I went straight to the docs, and start
                  looking for an explination. I couldn't find one, which is why I posted here.
                  I tried Ceiling and other methods to no avail.
                  [color=blue][color=green]
                  > > Whatever happened to the "No such thing as a
                  > > silly question, only a silly answer" way that *most* of the helpful[/color][/color]
                  people[color=blue][color=green]
                  > > in this group (and indeed this thread) seem to have?[/color]
                  >
                  > Well, it got readjusted by the RTFM attitude.[/color]

                  Only in some people :P

                  [color=blue]
                  > You may notice that I thoroughly explained WHY the problem occured, too.[/color]

                  Yes, you did. Unfortunately it was preceeded by "This is pretty obvious".

                  Sorry for not knowing C# inside out - believe it or not, that's because I'm
                  just starting to learn it... I do believe there's a gap between not knowing
                  a language and knowing it, and that's called learning.

                  [color=blue][color=green]
                  > > </rant>[/color]
                  >
                  > Read the langauge specs, and you dont have to rant.[/color]

                  Nor would I have to if you left the replying to the other helpful people
                  around here that posted, or at least left out the patronising sarcasm. Not
                  something I've seen (or expected) from an MVP before. Thanks.
                  --
                  Daisy The Cow
                  Now playing: Nothing


                  Comment

                  • Thomas Tomicek [MVP]

                    #10
                    Re: Maths &amp; Rounding

                    "Daisy" <daisy@nospam.o ops> wrote in message
                    news:bgblul$aqp $1@linux01.dann ytuppeny.com...[color=blue]
                    > "Thomas Tomicek [MVP]" <t.tomiczek@tho na-consulting.com> wrote in message
                    > news:uBATym4VDH A.1180@TK2MSFTN GP11.phx.gbl...[color=green]
                    > > Then read the language specification before you start using the[/color][/color]
                    language.[color=blue][color=green]
                    > > This is similar to the C / C++ way of handling things, and it is fully
                    > > documented in language specs.[/color]
                    >
                    > I don't know about you, but I have better things to do than RTFM front to
                    > back. I've done enough programming to know how maths works, so it would[/color]
                    have[color=blue]
                    > been rather a waste of time I could've been coding in. And since there are
                    > so many helpful people in groups like this, I decided to use the time
                    > coding.[/color]

                    What a sweet arrogance. "You have done enough programming to know how math
                    works", though this specs are clearly labelled and follow the behavior of VB
                    (if I remember right), definitly Java, C, C++.
                    [color=blue]
                    > And FYI, when I got the wrong result, I went straight to the docs, and[/color]
                    start[color=blue]
                    > looking for an explination. I couldn't find one, which is why I posted[/color]
                    here.[color=blue]
                    > I tried Ceiling and other methods to no avail.[/color]

                    Sure :-) Not to nag it, but you never read the language specs :-)
                    [color=blue][color=green]
                    > > You may notice that I thoroughly explained WHY the problem occured, too.[/color]
                    >
                    > Yes, you did. Unfortunately it was preceeded by "This is pretty obvious".[/color]

                    As it IS obvious.
                    [color=blue]
                    > Sorry for not knowing C# inside out - believe it or not, that's because[/color]
                    I'm[color=blue]
                    > just starting to learn it... I do believe there's a gap between not[/color]
                    knowing[color=blue]
                    > a language and knowing it, and that's called learning.[/color]

                    "Enough programming not to read the langauge", and never have used any of
                    the of the "mainstream " langauges (C/C++/java/pascal) etc. that have the
                    same behavior :-) Yes, I see.
                    [color=blue][color=green]
                    > > Read the langauge specs, and you dont have to rant.[/color]
                    >
                    > Nor would I have to if you left the replying to the other helpful people
                    > around here that posted, or at least left out the patronising sarcasm. Not
                    > something I've seen (or expected) from an MVP before. Thanks.[/color]

                    Well, I assume they knew me when they made me MVP. Can also be that my
                    answers are usually right and in enough detail to make people start
                    thinking.

                    --
                    Regards

                    Thomas Tomiczek
                    THONA Software & Consulting Ltd.
                    (Microsoft MVP C#/.NET)


                    Comment

                    • Thomas Tomicek [MVP]

                      #11
                      Re: Maths &amp; Rounding

                      "Daisy" <daisy@nospam.o ops> wrote in message
                      news:bgblul$aqp $1@linux01.dann ytuppeny.com...[color=blue]
                      > "Thomas Tomicek [MVP]" <t.tomiczek@tho na-consulting.com> wrote in message
                      > news:uBATym4VDH A.1180@TK2MSFTN GP11.phx.gbl...[color=green]
                      > > Then read the language specification before you start using the[/color][/color]
                      language.[color=blue][color=green]
                      > > This is similar to the C / C++ way of handling things, and it is fully
                      > > documented in language specs.[/color]
                      >
                      > I don't know about you, but I have better things to do than RTFM front to
                      > back. I've done enough programming to know how maths works, so it would[/color]
                      have[color=blue]
                      > been rather a waste of time I could've been coding in. And since there are
                      > so many helpful people in groups like this, I decided to use the time
                      > coding.[/color]

                      What a sweet arrogance. "You have done enough programming to know how math
                      works", though this specs are clearly labelled and follow the behavior of VB
                      (if I remember right), definitly Java, C, C++.
                      [color=blue]
                      > And FYI, when I got the wrong result, I went straight to the docs, and[/color]
                      start[color=blue]
                      > looking for an explination. I couldn't find one, which is why I posted[/color]
                      here.[color=blue]
                      > I tried Ceiling and other methods to no avail.[/color]

                      Sure :-) Not to nag it, but you never read the language specs :-)
                      [color=blue][color=green]
                      > > You may notice that I thoroughly explained WHY the problem occured, too.[/color]
                      >
                      > Yes, you did. Unfortunately it was preceeded by "This is pretty obvious".[/color]

                      As it IS obvious.
                      [color=blue]
                      > Sorry for not knowing C# inside out - believe it or not, that's because[/color]
                      I'm[color=blue]
                      > just starting to learn it... I do believe there's a gap between not[/color]
                      knowing[color=blue]
                      > a language and knowing it, and that's called learning.[/color]

                      "Enough programming not to read the langauge", and never have used any of
                      the of the "mainstream " langauges (C/C++/java/pascal) etc. that have the
                      same behavior :-) Yes, I see.
                      [color=blue][color=green]
                      > > Read the langauge specs, and you dont have to rant.[/color]
                      >
                      > Nor would I have to if you left the replying to the other helpful people
                      > around here that posted, or at least left out the patronising sarcasm. Not
                      > something I've seen (or expected) from an MVP before. Thanks.[/color]

                      Well, I assume they knew me when they made me MVP. Can also be that my
                      answers are usually right and in enough detail to make people start
                      thinking.

                      --
                      Regards

                      Thomas Tomiczek
                      THONA Software & Consulting Ltd.
                      (Microsoft MVP C#/.NET)


                      Comment

                      • Bill Priess

                        #12
                        Re: Maths &amp; Rounding

                        Well, I have to admit that I agree with Daisy. I have personally seen many
                        posts from her and although some of them are no brainers, for a learner,
                        she is usually well on track.

                        Not everyone here is a MVP, MCSE, MCSD. Not everyone has dealt with C/C++
                        or any other mainstream languages aside from MS ones.

                        As for the specs... most of us who have dealt with any of the mainstream
                        languages that MS has taken and bastardized (no offense, MSFT, but that is
                        usually the case) know that the specs are not always clearly written. For
                        instance, Math.Ceiling does not accept an int as a parameter *according to
                        the documenation*, but will take and implicitly convert an int to a double
                        in order to return a double. So, where in the documentation is that
                        mentioned? A learner who reads MSDN front to back is not going to find that
                        information easily, wouldn't you agree? In fact, to a learner,
                        Math.Ceiling(18 0/10) should return 2, but in fact, it doesn't. But,
                        according to the documentation posted here, it *should*.

                        As a matter of fact, here is the documentation from MSDN 2003 (April) which
                        does not show that an implicit conversion is taking place.


                        <paste>
                        ..NET Framework Class Library

                        Math.Ceiling Method [C#]See Also
                        Math Class | Math Members | System Namespace | Round | Floor Requirements
                        Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows
                        2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server
                        family
                        Language
                        C#

                        C++

                        JScript

                        Visual Basic

                        Show All
                        Returns the smallest whole number greater than or equal to the specified
                        number.

                        [Visual Basic]
                        Public Shared Function Ceiling( _
                        ByVal a As Double _
                        ) As Double
                        [C#]
                        public static double Ceiling(
                        double a
                        );
                        [C++]
                        public: static double Ceiling(
                        double a
                        );
                        [JScript]
                        public static function Ceiling(
                        a : double
                        ) : double;
                        Parameters
                        a A number. Return Value
                        The smallest whole number greater than or equal to a. If a is equal to NaN,
                        NegativeInfinit y, or PositiveInfinit y, that value is returned.

                        Remarks
                        The behavior of this method follows IEEE Standard 754, section 4. This kind
                        of rounding is sometimes called rounding toward positive infinity.

                        Requirements
                        Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows
                        2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server
                        family

                        See Also
                        Math Class | Math Members | System Namespace | Round | Floor


                        ----------------------------------------------------------------------------
                        ----

                        Send comments on this topic.

                        © 2001 Microsoft Corporation. All rights reserved. </paste>


                        Now, with that posted, where does RTFM come into play?

                        Bill P.


                        On Thu, 31 Jul 2003 21:48:16 +0200, Thomas Tomicek [MVP] <t.tomiczek@tho na-
                        consulting.com> wrote:
                        [color=blue]
                        > "Daisy" <daisy@nospam.o ops> wrote in message
                        > news:bgblul$aqp $1@linux01.dann ytuppeny.com...[color=green]
                        >> "Thomas Tomicek [MVP]" <t.tomiczek@tho na-consulting.com> wrote in
                        >> message
                        >> news:uBATym4VDH A.1180@TK2MSFTN GP11.phx.gbl...[color=darkred]
                        >> > Then read the language specification before you start using the[/color][/color]
                        > language.[color=green][color=darkred]
                        >> > This is similar to the C / C++ way of handling things, and it is fully
                        >> > documented in language specs.[/color]
                        >>
                        >> I don't know about you, but I have better things to do than RTFM front
                        >> to
                        >> back. I've done enough programming to know how maths works, so it would[/color]
                        > have[color=green]
                        >> been rather a waste of time I could've been coding in. And since there
                        >> are
                        >> so many helpful people in groups like this, I decided to use the time
                        >> coding.[/color]
                        >
                        > What a sweet arrogance. "You have done enough programming to know how
                        > math
                        > works", though this specs are clearly labelled and follow the behavior of
                        > VB
                        > (if I remember right), definitly Java, C, C++.
                        >[color=green]
                        >> And FYI, when I got the wrong result, I went straight to the docs, and[/color]
                        > start[color=green]
                        >> looking for an explination. I couldn't find one, which is why I posted[/color]
                        > here.[color=green]
                        >> I tried Ceiling and other methods to no avail.[/color]
                        >
                        > Sure :-) Not to nag it, but you never read the language specs :-)
                        >[color=green][color=darkred]
                        >> > You may notice that I thoroughly explained WHY the problem occured,[/color]
                        >> too.
                        >>
                        >> Yes, you did. Unfortunately it was preceeded by "This is pretty
                        >> obvious".[/color]
                        >
                        > As it IS obvious.
                        >[color=green]
                        >> Sorry for not knowing C# inside out - believe it or not, that's because[/color]
                        > I'm[color=green]
                        >> just starting to learn it... I do believe there's a gap between not[/color]
                        > knowing[color=green]
                        >> a language and knowing it, and that's called learning.[/color]
                        >
                        > "Enough programming not to read the langauge", and never have used any of
                        > the of the "mainstream " langauges (C/C++/java/pascal) etc. that have the
                        > same behavior :-) Yes, I see.
                        >[color=green][color=darkred]
                        >> > Read the langauge specs, and you dont have to rant.[/color]
                        >>
                        >> Nor would I have to if you left the replying to the other helpful people
                        >> around here that posted, or at least left out the patronising sarcasm.
                        >> Not
                        >> something I've seen (or expected) from an MVP before. Thanks.[/color]
                        >
                        > Well, I assume they knew me when they made me MVP. Can also be that my
                        > answers are usually right and in enough detail to make people start
                        > thinking.
                        >[/color]



                        --
                        Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

                        Comment

                        • Bill Priess

                          #13
                          Re: Maths &amp; Rounding

                          Well, I have to admit that I agree with Daisy. I have personally seen many
                          posts from her and although some of them are no brainers, for a learner,
                          she is usually well on track.

                          Not everyone here is a MVP, MCSE, MCSD. Not everyone has dealt with C/C++
                          or any other mainstream languages aside from MS ones.

                          As for the specs... most of us who have dealt with any of the mainstream
                          languages that MS has taken and bastardized (no offense, MSFT, but that is
                          usually the case) know that the specs are not always clearly written. For
                          instance, Math.Ceiling does not accept an int as a parameter *according to
                          the documenation*, but will take and implicitly convert an int to a double
                          in order to return a double. So, where in the documentation is that
                          mentioned? A learner who reads MSDN front to back is not going to find that
                          information easily, wouldn't you agree? In fact, to a learner,
                          Math.Ceiling(18 0/10) should return 2, but in fact, it doesn't. But,
                          according to the documentation posted here, it *should*.

                          As a matter of fact, here is the documentation from MSDN 2003 (April) which
                          does not show that an implicit conversion is taking place.


                          <paste>
                          ..NET Framework Class Library

                          Math.Ceiling Method [C#]See Also
                          Math Class | Math Members | System Namespace | Round | Floor Requirements
                          Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows
                          2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server
                          family
                          Language
                          C#

                          C++

                          JScript

                          Visual Basic

                          Show All
                          Returns the smallest whole number greater than or equal to the specified
                          number.

                          [Visual Basic]
                          Public Shared Function Ceiling( _
                          ByVal a As Double _
                          ) As Double
                          [C#]
                          public static double Ceiling(
                          double a
                          );
                          [C++]
                          public: static double Ceiling(
                          double a
                          );
                          [JScript]
                          public static function Ceiling(
                          a : double
                          ) : double;
                          Parameters
                          a A number. Return Value
                          The smallest whole number greater than or equal to a. If a is equal to NaN,
                          NegativeInfinit y, or PositiveInfinit y, that value is returned.

                          Remarks
                          The behavior of this method follows IEEE Standard 754, section 4. This kind
                          of rounding is sometimes called rounding toward positive infinity.

                          Requirements
                          Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows
                          2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server
                          family

                          See Also
                          Math Class | Math Members | System Namespace | Round | Floor


                          ----------------------------------------------------------------------------
                          ----

                          Send comments on this topic.

                          © 2001 Microsoft Corporation. All rights reserved. </paste>


                          Now, with that posted, where does RTFM come into play?

                          Bill P.


                          On Thu, 31 Jul 2003 21:48:16 +0200, Thomas Tomicek [MVP] <t.tomiczek@tho na-
                          consulting.com> wrote:
                          [color=blue]
                          > "Daisy" <daisy@nospam.o ops> wrote in message
                          > news:bgblul$aqp $1@linux01.dann ytuppeny.com...[color=green]
                          >> "Thomas Tomicek [MVP]" <t.tomiczek@tho na-consulting.com> wrote in
                          >> message
                          >> news:uBATym4VDH A.1180@TK2MSFTN GP11.phx.gbl...[color=darkred]
                          >> > Then read the language specification before you start using the[/color][/color]
                          > language.[color=green][color=darkred]
                          >> > This is similar to the C / C++ way of handling things, and it is fully
                          >> > documented in language specs.[/color]
                          >>
                          >> I don't know about you, but I have better things to do than RTFM front
                          >> to
                          >> back. I've done enough programming to know how maths works, so it would[/color]
                          > have[color=green]
                          >> been rather a waste of time I could've been coding in. And since there
                          >> are
                          >> so many helpful people in groups like this, I decided to use the time
                          >> coding.[/color]
                          >
                          > What a sweet arrogance. "You have done enough programming to know how
                          > math
                          > works", though this specs are clearly labelled and follow the behavior of
                          > VB
                          > (if I remember right), definitly Java, C, C++.
                          >[color=green]
                          >> And FYI, when I got the wrong result, I went straight to the docs, and[/color]
                          > start[color=green]
                          >> looking for an explination. I couldn't find one, which is why I posted[/color]
                          > here.[color=green]
                          >> I tried Ceiling and other methods to no avail.[/color]
                          >
                          > Sure :-) Not to nag it, but you never read the language specs :-)
                          >[color=green][color=darkred]
                          >> > You may notice that I thoroughly explained WHY the problem occured,[/color]
                          >> too.
                          >>
                          >> Yes, you did. Unfortunately it was preceeded by "This is pretty
                          >> obvious".[/color]
                          >
                          > As it IS obvious.
                          >[color=green]
                          >> Sorry for not knowing C# inside out - believe it or not, that's because[/color]
                          > I'm[color=green]
                          >> just starting to learn it... I do believe there's a gap between not[/color]
                          > knowing[color=green]
                          >> a language and knowing it, and that's called learning.[/color]
                          >
                          > "Enough programming not to read the langauge", and never have used any of
                          > the of the "mainstream " langauges (C/C++/java/pascal) etc. that have the
                          > same behavior :-) Yes, I see.
                          >[color=green][color=darkred]
                          >> > Read the langauge specs, and you dont have to rant.[/color]
                          >>
                          >> Nor would I have to if you left the replying to the other helpful people
                          >> around here that posted, or at least left out the patronising sarcasm.
                          >> Not
                          >> something I've seen (or expected) from an MVP before. Thanks.[/color]
                          >
                          > Well, I assume they knew me when they made me MVP. Can also be that my
                          > answers are usually right and in enough detail to make people start
                          > thinking.
                          >[/color]



                          --
                          Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

                          Comment

                          • Thomas Tomicek [MVP]

                            #14
                            Re: Maths &amp; Rounding

                            "Bill Priess" <no.spam@nospam .com> wrote in message
                            news:oprs63luv6 cimqky@localhos t...[color=blue]
                            > Well, I have to admit that I agree with Daisy. I have personally seen many
                            > posts from her and although some of them are no brainers, for a learner,
                            > she is usually well on track.
                            >
                            > Not everyone here is a MVP, MCSE, MCSD. Not everyone has dealt with C/C++
                            > or any other mainstream languages aside from MS ones.[/color]

                            Not everyone claims he knows the language without reading the specs.
                            [color=blue]
                            > As for the specs... most of us who have dealt with any of the mainstream
                            > languages that MS has taken and bastardized (no offense, MSFT, but that is
                            > usually the case) know that the specs are not always clearly written. For
                            > instance, Math.Ceiling does not accept an int as a parameter *according to
                            > the documenation*, but will take and implicitly convert an int to a double
                            > in order to return a double. So, where in the documentation is that
                            > mentioned? A learner who reads MSDN front to back is not going to find[/color]
                            that

                            It is properly documented in a lot of places. Look at the specifications on
                            the implicit transformations of valuue types. This is beginners section.

                            Just look at the documentation, in this case the C# Programmer's reference:

                            ms-help://MS.NETFramework SDKv1.1/csref/html/vclrfimplicitnu mericconversion .h
                            tm

                            It lists ALL implicit conversions.

                            Or, if you prefer the language specification:

                            ms-help://MS.NETFramework SDKv1.1/csspec/html/vclrfcsharpspec _6_1_2.htm

                            The whole chapter 6.1 of the language specifications lists all Implicit
                            conversions.

                            Thinking about them is your job.

                            Putting it mildly - I am happy you arew not a lawyer or a doctor, as not
                            making your homework would put you into jail pretty fast in these
                            businesses. If you loose in court, saaying "I wa just trying and never read
                            the law" is not a good excuse.
                            [color=blue]
                            > information easily, wouldn't you agree? In fact, to a learner,[/color]

                            I dont. I am a SELF-LEARNER. In contray to you, though, I propably took the
                            two hours to read the langauge specifications FIRST.
                            [color=blue]
                            > Math.Ceiling(18 0/10) should return 2, but in fact, it doesn't. But,
                            > according to the documentation posted here, it *should*.[/color]

                            No, it should NOT. This is pretty clear to anyone reading the math
                            documentation AND knowing the basics of how functions are evaluated.
                            [color=blue]
                            > As a matter of fact, here is the documentation from MSDN 2003 (April)[/color]
                            which[color=blue]
                            > does not show that an implicit conversion is taking place.[/color]
                            ....snipped...

                            Because it is not part of the method. It is part o the LANGUAGE, and it is
                            VERY properly documented. Links above. Referring to the method documentation
                            just shows you have a little brutally said a total disrespect for the
                            language. It is pretty clear that the INPUT into ceiling used is ONE
                            float/int/whatever, it is also clear that the mathematical expression is
                            evaluated FIRST.

                            NOW - this evaluation follows the rules laid out in.

                            You may want to try to understand sections:

                            7.2.6 Numeric promotions
                            and
                            7.4.2 Overload resolution

                            In combination with
                            7.2.1 Operator precedence and ssociativity
                            and
                            2.4.4.2 Integer literals

                            it is clear that
                            * 180/10 is evaluated first.
                            * 180 and 10 are integer literals
                            * 180 / 10 is performed as a division integer to integer

                            NOW - the documentation states (7.7.2, btw - Division Operator):

                            "The division rounds the result towards zero, and the absolute value of the
                            result is the largest possible integer that is less than the absolute value
                            of the quotient of the two operands"

                            So the output of 180 / 10 is clearly defined to be an integer, including the
                            rounding rules, as both inputs are integers. And THIS is what you put into
                            the Math.Ceiling method.

                            Surely all this is not documented in the Math.Ceiling method - it is of no
                            business to the method. It is basic arithmetic operations performed by the
                            langauge before the method sees the result of the operation.
                            [color=blue]
                            > Now, with that posted, where does RTFM come into play?[/color]

                            At the moment you learn the LANGUAGE and how it resolves the arithmetic
                            operation whose output you put into the method you took the freedom to
                            quote.

                            Just shows that when you dont know the language you want to program in, the
                            documentation of the library is of no use, and that no ibrary documentation
                            saves you from learning the langauge first. References are given through my
                            whole post, referring to the language specification, which is part of the
                            MSDN documentation OR can be found in the Framework documentation (less
                            weighty) under

                            ..NET Framework SDK / Reference / Compiler and Languag Reference / C# / C#
                            Language Specification

                            Thomas Tomiczek
                            THONA Software & Consulting Ltd.
                            (Microsoft MVP C#/.NET)


                            Comment

                            • Thomas Tomicek [MVP]

                              #15
                              Re: Maths &amp; Rounding

                              "Bill Priess" <no.spam@nospam .com> wrote in message
                              news:oprs63luv6 cimqky@localhos t...[color=blue]
                              > Well, I have to admit that I agree with Daisy. I have personally seen many
                              > posts from her and although some of them are no brainers, for a learner,
                              > she is usually well on track.
                              >
                              > Not everyone here is a MVP, MCSE, MCSD. Not everyone has dealt with C/C++
                              > or any other mainstream languages aside from MS ones.[/color]

                              Not everyone claims he knows the language without reading the specs.
                              [color=blue]
                              > As for the specs... most of us who have dealt with any of the mainstream
                              > languages that MS has taken and bastardized (no offense, MSFT, but that is
                              > usually the case) know that the specs are not always clearly written. For
                              > instance, Math.Ceiling does not accept an int as a parameter *according to
                              > the documenation*, but will take and implicitly convert an int to a double
                              > in order to return a double. So, where in the documentation is that
                              > mentioned? A learner who reads MSDN front to back is not going to find[/color]
                              that

                              It is properly documented in a lot of places. Look at the specifications on
                              the implicit transformations of valuue types. This is beginners section.

                              Just look at the documentation, in this case the C# Programmer's reference:

                              ms-help://MS.NETFramework SDKv1.1/csref/html/vclrfimplicitnu mericconversion .h
                              tm

                              It lists ALL implicit conversions.

                              Or, if you prefer the language specification:

                              ms-help://MS.NETFramework SDKv1.1/csspec/html/vclrfcsharpspec _6_1_2.htm

                              The whole chapter 6.1 of the language specifications lists all Implicit
                              conversions.

                              Thinking about them is your job.

                              Putting it mildly - I am happy you arew not a lawyer or a doctor, as not
                              making your homework would put you into jail pretty fast in these
                              businesses. If you loose in court, saaying "I wa just trying and never read
                              the law" is not a good excuse.
                              [color=blue]
                              > information easily, wouldn't you agree? In fact, to a learner,[/color]

                              I dont. I am a SELF-LEARNER. In contray to you, though, I propably took the
                              two hours to read the langauge specifications FIRST.
                              [color=blue]
                              > Math.Ceiling(18 0/10) should return 2, but in fact, it doesn't. But,
                              > according to the documentation posted here, it *should*.[/color]

                              No, it should NOT. This is pretty clear to anyone reading the math
                              documentation AND knowing the basics of how functions are evaluated.
                              [color=blue]
                              > As a matter of fact, here is the documentation from MSDN 2003 (April)[/color]
                              which[color=blue]
                              > does not show that an implicit conversion is taking place.[/color]
                              ....snipped...

                              Because it is not part of the method. It is part o the LANGUAGE, and it is
                              VERY properly documented. Links above. Referring to the method documentation
                              just shows you have a little brutally said a total disrespect for the
                              language. It is pretty clear that the INPUT into ceiling used is ONE
                              float/int/whatever, it is also clear that the mathematical expression is
                              evaluated FIRST.

                              NOW - this evaluation follows the rules laid out in.

                              You may want to try to understand sections:

                              7.2.6 Numeric promotions
                              and
                              7.4.2 Overload resolution

                              In combination with
                              7.2.1 Operator precedence and ssociativity
                              and
                              2.4.4.2 Integer literals

                              it is clear that
                              * 180/10 is evaluated first.
                              * 180 and 10 are integer literals
                              * 180 / 10 is performed as a division integer to integer

                              NOW - the documentation states (7.7.2, btw - Division Operator):

                              "The division rounds the result towards zero, and the absolute value of the
                              result is the largest possible integer that is less than the absolute value
                              of the quotient of the two operands"

                              So the output of 180 / 10 is clearly defined to be an integer, including the
                              rounding rules, as both inputs are integers. And THIS is what you put into
                              the Math.Ceiling method.

                              Surely all this is not documented in the Math.Ceiling method - it is of no
                              business to the method. It is basic arithmetic operations performed by the
                              langauge before the method sees the result of the operation.
                              [color=blue]
                              > Now, with that posted, where does RTFM come into play?[/color]

                              At the moment you learn the LANGUAGE and how it resolves the arithmetic
                              operation whose output you put into the method you took the freedom to
                              quote.

                              Just shows that when you dont know the language you want to program in, the
                              documentation of the library is of no use, and that no ibrary documentation
                              saves you from learning the langauge first. References are given through my
                              whole post, referring to the language specification, which is part of the
                              MSDN documentation OR can be found in the Framework documentation (less
                              weighty) under

                              ..NET Framework SDK / Reference / Compiler and Languag Reference / C# / C#
                              Language Specification

                              Thomas Tomiczek
                              THONA Software & Consulting Ltd.
                              (Microsoft MVP C#/.NET)


                              Comment

                              Working...