Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. BUG in Windows Calc [modified]

BUG in Windows Calc [modified]

Scheduled Pinned Locked Moved The Lounge
comsysadminwindows-admintoolshelp
64 Posts 36 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P peterchen

    Actually, Calc internals have been replaced (around XP) with a long numbers library, so it is somehow noteworthy that this isn't enough. OTOH, the OP failed to notice tha 8e-39 is zero enough when playing around with square roots of 2.

    Agh! Reality! My Archnemesis![^]
    | FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchy

    L Offline
    L Offline
    leppie
    wrote on last edited by
    #29

    peterchen wrote:

    OTOH, the OP failed to notice tha 8e-39 is zero enough when playing around with square roots of 2.

    And that is why I cleverly did not point out who the FAILER actually was ;P

    ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

    1 Reply Last reply
    0
    • P peterchen

      Actually, Calc internals have been replaced (around XP) with a long numbers library, so it is somehow noteworthy that this isn't enough. OTOH, the OP failed to notice tha 8e-39 is zero enough when playing around with square roots of 2.

      Agh! Reality! My Archnemesis![^]
      | FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchy

      Q Offline
      Q Offline
      QuiJohn
      wrote on last edited by
      #30

      peterchen wrote:

      Actually, Calc internals have been replaced (around XP) with a long numbers library, so it is somehow noteworthy that this isn't enough.

      I actually thought I heard it referred to as an "infinite precision" calculator. I've tested it before on values that would make the pre-XP calc choke, but apparently it's not infinite. Ah, googled it... apparently "arbitrary" precision is what it's called. I think MS changed it in the wake of that idiotic, much publicized and ultimately harmless Pentium "floating point" bug. People kept thinking they were finding more bugs, but they were just running into typical floating point inaccuracies.


      He said, "Boy I'm just old and lonely, But thank you for your concern, Here's wishing you a Happy New Year." I wished him one back in return.

      1 Reply Last reply
      0
      • L leppie

        Another fails the knowledge about floating point.... When will they ever learn????? Edit: It seems to happen with any rounding around 0. If your result is not 0, the result is correctly rounded, but with values very near 0, it simply 'forgets'.... Edit 2: Press = again, the answer will be -2 as expected confirming the previous value is not rounded correctly, but still good enough due to its 'smallness' (e-39 is very small).

        ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

        modified on Monday, November 1, 2010 7:07 AM

        D Offline
        D Offline
        Dan Neely
        wrote on last edited by
        #31

        leppie wrote:

        Another fails the knowledge about floating point.... When will they ever learn?????

        ... not until this[^] (What Every Computer Scientist Should Know About Floating-Point Arithmetic) is added to the standard curriculum. :sigh: :sigh:

        3x12=36 2x12=24 1x12=12 0x12=18

        1 Reply Last reply
        0
        • H Hiren solanki

          Follow the procedure click '4' click 'sqrt' click '-'(Minus sign) click '2' Answer should be 0 But It comes back with '-8.1648465955514287168521180122928e-39' answer ;P [Edit] Tested with XP and Seven _[/More Edit] Windows Server 2008 R2 comes same with yet another answer '-1.068281969439142e-19' _[/More Edit] [/Edit]

          Rating is Always appreciated.
          Regards,
          Hiren Solanki.
          Indian Forum | My Articles | My Profile


          "You will always find me near 127.0.0.1"

          modified on Monday, November 1, 2010 7:00 AM

          R Offline
          R Offline
          Roger Wright
          wrote on last edited by
          #32

          It's called rounding error, and the problem has been around since computers ran on vacuum tubes. The error has become smaller over the years as bits have been added to operands, but it still occurs due the fact that the finite representation of values which are not, in fact, expressible as a mantissa and a fixed length exponent, can contain a small error. It happens to be very noticeable around zero, but it's present in all FP calculations. It is for that reason programmers have been taught for decades never to use a comparison to zero when the control variable is calcuated using floating point math. It leads to expressions like:

          if ((x - k =< 0)|(x + k =< 0))
          {
          DoSomeThingUsefulBecauseXisZero();
          }

          The if argument tests for x = 0, +/- k, a constant value. It stumped me when I first saw it in missle guidance test code, until my boss reminded me of what I'd been taught in my only programming class a few years earlier - a bit embarrassing... :-O Have they finally stopped teaching this? :-D

          Will Rogers never met me.

          H 1 Reply Last reply
          0
          • L leppie

            Another fails the knowledge about floating point.... When will they ever learn????? Edit: It seems to happen with any rounding around 0. If your result is not 0, the result is correctly rounded, but with values very near 0, it simply 'forgets'.... Edit 2: Press = again, the answer will be -2 as expected confirming the previous value is not rounded correctly, but still good enough due to its 'smallness' (e-39 is very small).

            ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

            modified on Monday, November 1, 2010 7:07 AM

            N Offline
            N Offline
            Nish Nishant
            wrote on last edited by
            #33

            It's still kinda ironic that cheap calculators from 20 years back will still display what the end-user wants to see, while a sophisticated OS comes with a calculator app that thinks it's okay to let its internal workings leak onto the UI.

            Regards, Nish


            My technology blog: voidnish.wordpress.com Code Project Forums : New Posts Monitor This application monitors for new posts in the Code Project forums.

            L 1 Reply Last reply
            0
            • N Nish Nishant

              It's still kinda ironic that cheap calculators from 20 years back will still display what the end-user wants to see, while a sophisticated OS comes with a calculator app that thinks it's okay to let its internal workings leak onto the UI.

              Regards, Nish


              My technology blog: voidnish.wordpress.com Code Project Forums : New Posts Monitor This application monitors for new posts in the Code Project forums.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #34

              I still have my first calculator from around 30 years ago, still on its original battery. Still works but takes a good few seconds to respond to each key press. I also still have my alarm clock radio at the side of my bed that I got for my 8th birthday (28 years ago last month). Still keeps and displays perfect time although it is many years since I have tried the alarm or radio out.

              Every man can tell how many goats or sheep he possesses, but not how many friends.

              1 Reply Last reply
              0
              • R Roger Wright

                It's called rounding error, and the problem has been around since computers ran on vacuum tubes. The error has become smaller over the years as bits have been added to operands, but it still occurs due the fact that the finite representation of values which are not, in fact, expressible as a mantissa and a fixed length exponent, can contain a small error. It happens to be very noticeable around zero, but it's present in all FP calculations. It is for that reason programmers have been taught for decades never to use a comparison to zero when the control variable is calcuated using floating point math. It leads to expressions like:

                if ((x - k =< 0)|(x + k =< 0))
                {
                DoSomeThingUsefulBecauseXisZero();
                }

                The if argument tests for x = 0, +/- k, a constant value. It stumped me when I first saw it in missle guidance test code, until my boss reminded me of what I'd been taught in my only programming class a few years earlier - a bit embarrassing... :-O Have they finally stopped teaching this? :-D

                Will Rogers never met me.

                H Offline
                H Offline
                Hiren solanki
                wrote on last edited by
                #35

                Take a 5 for deep description.

                Rating is Always appreciated.
                Regards,
                Hiren Solanki.
                Indian Forum | My Articles | My Profile


                "You will always find me near 127.0.0.1"

                1 Reply Last reply
                0
                • H Hiren solanki

                  Follow the procedure click '4' click 'sqrt' click '-'(Minus sign) click '2' Answer should be 0 But It comes back with '-8.1648465955514287168521180122928e-39' answer ;P [Edit] Tested with XP and Seven _[/More Edit] Windows Server 2008 R2 comes same with yet another answer '-1.068281969439142e-19' _[/More Edit] [/Edit]

                  Rating is Always appreciated.
                  Regards,
                  Hiren Solanki.
                  Indian Forum | My Articles | My Profile


                  "You will always find me near 127.0.0.1"

                  modified on Monday, November 1, 2010 7:00 AM

                  E Offline
                  E Offline
                  Ennis Ray Lynch Jr
                  wrote on last edited by
                  #36

                  Not a bug.

                  Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

                  1 Reply Last reply
                  0
                  • H Hiren solanki

                    Follow the procedure click '4' click 'sqrt' click '-'(Minus sign) click '2' Answer should be 0 But It comes back with '-8.1648465955514287168521180122928e-39' answer ;P [Edit] Tested with XP and Seven _[/More Edit] Windows Server 2008 R2 comes same with yet another answer '-1.068281969439142e-19' _[/More Edit] [/Edit]

                    Rating is Always appreciated.
                    Regards,
                    Hiren Solanki.
                    Indian Forum | My Articles | My Profile


                    "You will always find me near 127.0.0.1"

                    modified on Monday, November 1, 2010 7:00 AM

                    L Offline
                    L Offline
                    ltj7708
                    wrote on last edited by
                    #37

                    It appears this will happen with any positive number, if the subtracted value is what should be the square root. For example: click '25' click 'sqrt' click '-' click '5' or click '39.955041' click 'sqrt' click '-' click '6.321' strange...

                    1 Reply Last reply
                    0
                    • H Hiren solanki

                      Follow the procedure click '4' click 'sqrt' click '-'(Minus sign) click '2' Answer should be 0 But It comes back with '-8.1648465955514287168521180122928e-39' answer ;P [Edit] Tested with XP and Seven _[/More Edit] Windows Server 2008 R2 comes same with yet another answer '-1.068281969439142e-19' _[/More Edit] [/Edit]

                      Rating is Always appreciated.
                      Regards,
                      Hiren Solanki.
                      Indian Forum | My Articles | My Profile


                      "You will always find me near 127.0.0.1"

                      modified on Monday, November 1, 2010 7:00 AM

                      W Offline
                      W Offline
                      wibleywoo
                      wrote on last edited by
                      #38

                      As expected same error occures with: 9 sqrt - 3 16 sqrt - 4 ...

                      1 Reply Last reply
                      0
                      • H Hiren solanki

                        Follow the procedure click '4' click 'sqrt' click '-'(Minus sign) click '2' Answer should be 0 But It comes back with '-8.1648465955514287168521180122928e-39' answer ;P [Edit] Tested with XP and Seven _[/More Edit] Windows Server 2008 R2 comes same with yet another answer '-1.068281969439142e-19' _[/More Edit] [/Edit]

                        Rating is Always appreciated.
                        Regards,
                        Hiren Solanki.
                        Indian Forum | My Articles | My Profile


                        "You will always find me near 127.0.0.1"

                        modified on Monday, November 1, 2010 7:00 AM

                        E Offline
                        E Offline
                        ErikKnowles
                        wrote on last edited by
                        #39

                        Oh geez, this is *not* a bug. Do you have *any* idea of how floating point math is performed? Internal vs. reported precision? You're a programmer??? I'm gobsmacked that this got posted to a code developer site. Oh, and you made CodeProject's daily e-mail, so your ignorance has been transmitted worldwide. Epic fail.

                        modified on Tuesday, November 2, 2010 4:35 PM

                        D 1 Reply Last reply
                        0
                        • K Keith Barrow

                          Sheesh, it's about right, whaddaya want, accuracy :-)

                          Sort of a cross between Lawrence of Arabia and Dilbert.[^]

                          O Offline
                          O Offline
                          oconnellc
                          wrote on last edited by
                          #40

                          Actually, it is accurate. Its problem is that it is *too* precise. If it was a little less precise, it would have decided that it was close enough to zero to just display zero.

                          J 1 Reply Last reply
                          0
                          • H Hiren solanki

                            Follow the procedure click '4' click 'sqrt' click '-'(Minus sign) click '2' Answer should be 0 But It comes back with '-8.1648465955514287168521180122928e-39' answer ;P [Edit] Tested with XP and Seven _[/More Edit] Windows Server 2008 R2 comes same with yet another answer '-1.068281969439142e-19' _[/More Edit] [/Edit]

                            Rating is Always appreciated.
                            Regards,
                            Hiren Solanki.
                            Indian Forum | My Articles | My Profile


                            "You will always find me near 127.0.0.1"

                            modified on Monday, November 1, 2010 7:00 AM

                            B Offline
                            B Offline
                            bwallan
                            wrote on last edited by
                            #41

                            Interesting BUT the Scientific view doesn't have a "sqrt" key; however, the x^y gives the same BUG... bwa

                            1 Reply Last reply
                            0
                            • H Hiren solanki

                              Follow the procedure click '4' click 'sqrt' click '-'(Minus sign) click '2' Answer should be 0 But It comes back with '-8.1648465955514287168521180122928e-39' answer ;P [Edit] Tested with XP and Seven _[/More Edit] Windows Server 2008 R2 comes same with yet another answer '-1.068281969439142e-19' _[/More Edit] [/Edit]

                              Rating is Always appreciated.
                              Regards,
                              Hiren Solanki.
                              Indian Forum | My Articles | My Profile


                              "You will always find me near 127.0.0.1"

                              modified on Monday, November 1, 2010 7:00 AM

                              P Offline
                              P Offline
                              Plamen Dragiyski
                              wrote on last edited by
                              #42

                              Woooow, I always use scientific calc in XP and I didn't know it is support sqrt... it seems that they forget to add that button into scientific dialog :laugh:

                              1 Reply Last reply
                              0
                              • O oconnellc

                                Actually, it is accurate. Its problem is that it is *too* precise. If it was a little less precise, it would have decided that it was close enough to zero to just display zero.

                                J Offline
                                J Offline
                                Jake Barney
                                wrote on last edited by
                                #43

                                In this particular instance any answer other than -4 or 0 is inaccurate. Doesn't matter that most of us understand that anything ^-39 power is so small as to be considered zero by most, it's still not zero. Understandably the answer they factored was 1.9999...8164whatever but its funny that the calculator rounded up, then 'forgot' that it did so. Sounds like sloppy programming. What's really funny is change it to the scientific calculator, do 4^.5 power then -2 and it gives a different answer.

                                1 Reply Last reply
                                0
                                • H Hiren solanki

                                  Follow the procedure click '4' click 'sqrt' click '-'(Minus sign) click '2' Answer should be 0 But It comes back with '-8.1648465955514287168521180122928e-39' answer ;P [Edit] Tested with XP and Seven _[/More Edit] Windows Server 2008 R2 comes same with yet another answer '-1.068281969439142e-19' _[/More Edit] [/Edit]

                                  Rating is Always appreciated.
                                  Regards,
                                  Hiren Solanki.
                                  Indian Forum | My Articles | My Profile


                                  "You will always find me near 127.0.0.1"

                                  modified on Monday, November 1, 2010 7:00 AM

                                  S Offline
                                  S Offline
                                  Sasa Cetkovic
                                  wrote on last edited by
                                  #44

                                  On Windows Server 2008 R2 it gives the first answer in scientific mode, and the second in standard mode.

                                  1 Reply Last reply
                                  0
                                  • H Hiren solanki

                                    Follow the procedure click '4' click 'sqrt' click '-'(Minus sign) click '2' Answer should be 0 But It comes back with '-8.1648465955514287168521180122928e-39' answer ;P [Edit] Tested with XP and Seven _[/More Edit] Windows Server 2008 R2 comes same with yet another answer '-1.068281969439142e-19' _[/More Edit] [/Edit]

                                    Rating is Always appreciated.
                                    Regards,
                                    Hiren Solanki.
                                    Indian Forum | My Articles | My Profile


                                    "You will always find me near 127.0.0.1"

                                    modified on Monday, November 1, 2010 7:00 AM

                                    D Offline
                                    D Offline
                                    David C Thompson
                                    wrote on last edited by
                                    #45

                                    It works (well, the bug works) with any number. I tried sqrt(25) - 5 and sqrt(9) - :^)

                                    1 Reply Last reply
                                    0
                                    • E ErikKnowles

                                      Oh geez, this is *not* a bug. Do you have *any* idea of how floating point math is performed? Internal vs. reported precision? You're a programmer??? I'm gobsmacked that this got posted to a code developer site. Oh, and you made CodeProject's daily e-mail, so your ignorance has been transmitted worldwide. Epic fail.

                                      modified on Tuesday, November 2, 2010 4:35 PM

                                      D Offline
                                      D Offline
                                      David C Thompson
                                      wrote on last edited by
                                      #46

                                      Can you enlighten those of us who may not be as well-informed as you?

                                      1 Reply Last reply
                                      0
                                      • H Hiren solanki

                                        Follow the procedure click '4' click 'sqrt' click '-'(Minus sign) click '2' Answer should be 0 But It comes back with '-8.1648465955514287168521180122928e-39' answer ;P [Edit] Tested with XP and Seven _[/More Edit] Windows Server 2008 R2 comes same with yet another answer '-1.068281969439142e-19' _[/More Edit] [/Edit]

                                        Rating is Always appreciated.
                                        Regards,
                                        Hiren Solanki.
                                        Indian Forum | My Articles | My Profile


                                        "You will always find me near 127.0.0.1"

                                        modified on Monday, November 1, 2010 7:00 AM

                                        C Offline
                                        C Offline
                                        Caslen
                                        wrote on last edited by
                                        #47

                                        For all you Numptys who this this is a bug - you can easily prove that it isn't, follow these simple steps:- 1. Convert the number 4 to a binary floating point representation and write it down. 2. Continue with your pen and paper and using a suitably selected algorithm to calculate the square root of a number presented in binary floating point form work out the square root of the binary floating point representation of the number 4 found in step 1. 3. Convert the number 2 into a binary floating point form (preferably the same form as that used in step 1) 4. Perform a floating point binary subtract on the result of step 3 from the result of step 4. 5. Do you have zero? No you do not!

                                        N T 2 Replies Last reply
                                        0
                                        • P peterchen

                                          Actually, Calc internals have been replaced (around XP) with a long numbers library, so it is somehow noteworthy that this isn't enough. OTOH, the OP failed to notice tha 8e-39 is zero enough when playing around with square roots of 2.

                                          Agh! Reality! My Archnemesis![^]
                                          | FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchy

                                          M Offline
                                          M Offline
                                          Michael Kingsford Gray
                                          wrote on last edited by
                                          #48

                                          It needs to do it like HP calculators have always done.

                                          P 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups