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. Other Discussions
  3. Clever Code
  4. I hate floating point operations

I hate floating point operations

Scheduled Pinned Locked Moved Clever Code
c++comquestion
63 Posts 24 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.
  • T Tim Smith

    WTF are you talking about? Please read about floating addition and multiplication. http://en.wikipedia.org/wiki/Floating_point#Floating_point_arithmetic_operations[^] Even though both suffer from rounding problems, multiplication doesn't suffer from "cancellation or absorption problems". I have run into many instances where addition based algorithms had huge precision problems that were eliminated by recoding the software to be more multiplication based.

    Tim Smith I'm going to patent thought. I have yet to see any prior art.

    K Offline
    K Offline
    KaRl
    wrote on last edited by
    #54

    Tim Smith wrote:

    WTF are you talking about?

    It was about rounding precision, but it doesn't matter, I don't seem able to make myslf understood in that thread :sigh:

    Tim Smith wrote:

    http://en.wikipedia.org/wiki/Floating\_point#Floating\_point\_arithmetic\_operations\[^\]

    Thanks for the link.


    Where do you expect us to go when the bombs fall?

    Fold with us! ¤ flickr

    1 Reply Last reply
    0
    • D Duncan Edwards Jones

      Yeah - floating point numbers should be called "approximate" to remind us not to use them when we want exact figures.

      '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #55

      Ah, yes, "approximate" and "doubly approximate". Then maybe David St. Hubbins' girlfriend's statement "you should do it in doubly" might make some sense.

      1 Reply Last reply
      0
      • R rollei35guy

        There used to be a warning message that stated 'equality comparisions between floating point values may not be meaningful.' or something like that. of course that was a long time ago on a Fortran compiler...;) Didn't this come up a month or so ago???

        K Offline
        K Offline
        KaRl
        wrote on last edited by
        #56

        rollei35guy wrote:

        that was a long time ago on a Fortran compiler

        It can be put in the 'positive points about fortran' column... That makes two, with the efficient math libraries (matrix were well handled IIRC) :)


        Where do you expect us to go when the bombs fall?

        Fold with us! ¤ flickr

        R 1 Reply Last reply
        0
        • P peterchen

          Floating point values stump the brightest. A week or two ago, I had an argument with an quite bright student, I only barely won :cool:


          Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers!
          We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
          Linkify!|Fold With Us!

          K Offline
          K Offline
          KaRl
          wrote on last edited by
          #57

          Where did you hide the body? :-D


          Where do you expect us to go when the bombs fall?

          Fold with us! ¤ flickr

          P 1 Reply Last reply
          0
          • K KaRl

            rollei35guy wrote:

            that was a long time ago on a Fortran compiler

            It can be put in the 'positive points about fortran' column... That makes two, with the efficient math libraries (matrix were well handled IIRC) :)


            Where do you expect us to go when the bombs fall?

            Fold with us! ¤ flickr

            R Offline
            R Offline
            rollei35guy
            wrote on last edited by
            #58

            K(arl) wrote:

            It can be put in the 'positive points about fortran' column... That makes two, with the efficient math libraries (matrix were well handled IIRC)

            :laugh:

            1 Reply Last reply
            0
            • R realJSOP

              When I was writing a tax calculation app many years ago, I wrote a function called AlmostEqual that looked something like this: bool AlmostEqual(double nVal1, double nVal2, int nPrecision) { CString sVal1; CString sVal2; nPrecision = _min(16, nPrecision); sVal1.Format("%.*lf", nPrecision, nVal1); sVal2.Format("%.*lf", nPrecision, nVal2); return (sVal1 == sVal2); } We had a need to check for equality at different precisions depending on where in the calculation cycle we were. I'm sure you can come up with many other ways to do the same thing, but this was fast and worked very well.

              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
              -----
              "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

              K Offline
              K Offline
              KaRl
              wrote on last edited by
              #59

              Interesting, and original.


              Where do you expect us to go when the bombs fall?

              Fold with us! ¤ flickr

              A 1 Reply Last reply
              0
              • K KaRl

                Where did you hide the body? :-D


                Where do you expect us to go when the bombs fall?

                Fold with us! ¤ flickr

                P Offline
                P Offline
                peterchen
                wrote on last edited by
                #60

                He was last seen "alive" in the hardware R&D department. :cool:


                Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers!
                We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
                Linkify!|Fold With Us!

                1 Reply Last reply
                0
                • K KaRl

                  Interesting, and original.


                  Where do you expect us to go when the bombs fall?

                  Fold with us! ¤ flickr

                  A Offline
                  A Offline
                  Anna Jayne Metcalfe
                  wrote on last edited by
                  #61

                  That's one way of putting it. :omg:

                  Anna :rose: Linting the day away :cool: Anna's Place | Tears and Laughter "If mushy peas are the food of the devil, the stotty cake is the frisbee of God"

                  1 Reply Last reply
                  0
                  • 1 123 0

                    K(arl) wrote:

                    I hate floating point operations

                    So do we. Any data type where "equality of values" is ill-defined is clearly half-baked. Someone should have put a more thought and less transistors into the matter.

                    A Offline
                    A Offline
                    Andy Brummer
                    wrote on last edited by
                    #62

                    The concept of numerical equality is a human concept that you are trying to enforce on a world where it doesn't exist. Two lengths are never exactly equal. Any collection of particles will always have virtual particles which are constantly being created and destroyed. If you say I have two baseballs or 5 nails, none of those objects are the same, you are only counting the number of objects that fit the abstract concept of baseball or nail. Exact equality only works with these abstract concepts. If you take that approach, floating point values are a good representation of lengths because lengths get the same errors when you add and multiply them using physical tools like a straightedge and compass. Integers and scaled are a better fit for abstract concepts like money which isn't a real thing.

                    Using the GridView is like trying to explain to someone else how to move a third person's hands in order to tie your shoelaces for you. -Chris Maunder

                    1 Reply Last reply
                    0
                    • C Chris Maunder

                      There are an awful lot of irrational numbers out there. I think I would rather have my planes and bridges built using a floating point approximation of PI rather than 355/113 >In either case, the concept of "equal values" can be defined and implemented with rigor, consistency, and reliability. It's a pity these concepts don't actually appear in real life. You postulate that the universe isn't continous but is discrete, implying you believ in quantum theory, yet the basis of quantum theory itself is that there is an inherent uncertainty in all measurements. >Secondly, as popular as the metric system may be in many countries, we find it much less effective in everyday life than the English system. That's because you live in a country that uses the Imperial system. I buy food that is weighed in grams, and buy petrol and milk in litres, and need to know how many kilometres there are till my turnoff. If I ever talk in halves or quarters I mean it in a vague way ("half a loaf of bread, please") and there is no need for accuracy.

                      cheers, Chris Maunder

                      CodeProject.com : C++ MVP

                      J Offline
                      J Offline
                      JBurkey
                      wrote on last edited by
                      #63

                      Also don't forget - There is a wave nature to light. The universe may be considered discreet for SOME applications, but there is a duality to matter. Every object has a wavelength... I suppose we don't need calculus anymore - what use are derivatives anyway? We'll just cut everything into super tiny rectangles, since a wave can't have a continuous curve...What was Newton thinking?

                      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