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. General Programming
  3. C / C++ / MFC
  4. Elliminate the e symbol from doubles

Elliminate the e symbol from doubles

Scheduled Pinned Locked Moved C / C++ / MFC
17 Posts 6 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.
  • C CPallini

    Blood_HaZaRd wrote:

    not a formatting proc for a printing on screen but for calculation)

    That makes no sense. :)

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
    [My articles]

    S Offline
    S Offline
    Schehaider_Aymen
    wrote on last edited by
    #4

    ok i'll try to give a little exmp : let's sy i have a double x= 1.123456789 e09 . i'd like to make it x = 1123456789 without the e right. is it clear or still fuzzy :s

    "The Ultimate Limit Is Only Your Imagination."

    C 1 Reply Last reply
    0
    • N Niklas L

      What you 'see' is a formatted string representation of the actual value. You do not lose accuracy in calculations just because the string looks truncated.

      home

      S Offline
      S Offline
      Schehaider_Aymen
      wrote on last edited by
      #5

      ok o how could u explain this : i have double x = 105145010021234567890311169400. and when i make double y = fmod(x, 97) it gives me 16 or when i calculte it with a calculator it gives me 92

      "The Ultimate Limit Is Only Your Imagination."

      N A 3 Replies Last reply
      0
      • S Schehaider_Aymen

        ok i'll try to give a little exmp : let's sy i have a double x= 1.123456789 e09 . i'd like to make it x = 1123456789 without the e right. is it clear or still fuzzy :s

        "The Ultimate Limit Is Only Your Imagination."

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #6

        Blood_HaZaRd wrote:

        x= 1.123456789 e09

        Blood_HaZaRd wrote:

        x = 1123456789

        Since they are different representations of the same number, both of them are stored, in a double, with the same bit pattern. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        S 1 Reply Last reply
        0
        • C CPallini

          Blood_HaZaRd wrote:

          x= 1.123456789 e09

          Blood_HaZaRd wrote:

          x = 1123456789

          Since they are different representations of the same number, both of them are stored, in a double, with the same bit pattern. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          S Offline
          S Offline
          Schehaider_Aymen
          wrote on last edited by
          #7

          it's clear that they have the same number but God its seems that the fmod doesn't make a correct modulo with double or i missed sth else with that fucntion ...

          //i have x = 105145010021234567890311169400 which is also equal to 1.0514501002123e+029
          double alpha = fmod (x, 97) //alpha will be equal to 16.000000000000

          or with calculator x modulo 97 = 92 it sounds my computer is hollowed :doh:

          "The Ultimate Limit Is Only Your Imagination."

          C 1 Reply Last reply
          0
          • S Schehaider_Aymen

            ok o how could u explain this : i have double x = 105145010021234567890311169400. and when i make double y = fmod(x, 97) it gives me 16 or when i calculte it with a calculator it gives me 92

            "The Ultimate Limit Is Only Your Imagination."

            N Offline
            N Offline
            Niklas L
            wrote on last edited by
            #8

            Your value cannot be stored within a double precision floating point number (64 bit IEEE whatever) It simply holds too much information, so your system will have to round it off.

            home

            1 Reply Last reply
            0
            • S Schehaider_Aymen

              ok o how could u explain this : i have double x = 105145010021234567890311169400. and when i make double y = fmod(x, 97) it gives me 16 or when i calculte it with a calculator it gives me 92

              "The Ultimate Limit Is Only Your Imagination."

              N Offline
              N Offline
              Niklas L
              wrote on last edited by
              #9

              Read about Floating point numbers[^]

              home

              1 Reply Last reply
              0
              • S Schehaider_Aymen

                ok o how could u explain this : i have double x = 105145010021234567890311169400. and when i make double y = fmod(x, 97) it gives me 16 or when i calculte it with a calculator it gives me 92

                "The Ultimate Limit Is Only Your Imagination."

                A Offline
                A Offline
                Aescleal
                wrote on last edited by
                #10

                You'll never get a representation of that integer into a double without loosing a chunk of accuracy. 105145010021234567890311169400 is 0xE97804B9A34AB4E which is going to take about 60 bits to hold. As a double only has 53 bits to store digits you've already rounded your number to the nearest multiple of 128 by storing it in a double. So as it's an integer, store it in an integer - the e bit is non-negotiable with a floating point number and has no bearing at all on your problem. Ash

                S 1 Reply Last reply
                0
                • A Aescleal

                  You'll never get a representation of that integer into a double without loosing a chunk of accuracy. 105145010021234567890311169400 is 0xE97804B9A34AB4E which is going to take about 60 bits to hold. As a double only has 53 bits to store digits you've already rounded your number to the nearest multiple of 128 by storing it in a double. So as it's an integer, store it in an integer - the e bit is non-negotiable with a floating point number and has no bearing at all on your problem. Ash

                  S Offline
                  S Offline
                  Schehaider_Aymen
                  wrote on last edited by
                  #11

                  ok so the best solution is to navigate into mthemticl splitting and mke the purpose by slices

                  "The Ultimate Limit Is Only Your Imagination."

                  N 1 Reply Last reply
                  0
                  • S Schehaider_Aymen

                    it's clear that they have the same number but God its seems that the fmod doesn't make a correct modulo with double or i missed sth else with that fucntion ...

                    //i have x = 105145010021234567890311169400 which is also equal to 1.0514501002123e+029
                    double alpha = fmod (x, 97) //alpha will be equal to 16.000000000000

                    or with calculator x modulo 97 = 92 it sounds my computer is hollowed :doh:

                    "The Ultimate Limit Is Only Your Imagination."

                    C Offline
                    C Offline
                    CPallini
                    wrote on last edited by
                    #12

                    Blood_HaZaRd wrote:

                    //i have x = 105145010021234567890311169400 which is also equal to 1.0514501002123e+029

                    That is wrong. As I stated before, double cannot represent such big integer numbers with the required (by you) accuracy:

                    1.0514501002123e+029 = 105145010021230000000000000000

                    i.e. there's a big difference with 105145010021234567890311169400. Bottom line: you cannot use a double for the intended purpose (after all, doubles are 64 bit numbers: they would have 'mystical powers' in order to represent an integer better than a 64 bit int itself). :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    S 1 Reply Last reply
                    0
                    • C CPallini

                      Blood_HaZaRd wrote:

                      //i have x = 105145010021234567890311169400 which is also equal to 1.0514501002123e+029

                      That is wrong. As I stated before, double cannot represent such big integer numbers with the required (by you) accuracy:

                      1.0514501002123e+029 = 105145010021230000000000000000

                      i.e. there's a big difference with 105145010021234567890311169400. Bottom line: you cannot use a double for the intended purpose (after all, doubles are 64 bit numbers: they would have 'mystical powers' in order to represent an integer better than a 64 bit int itself). :)

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                      [My articles]

                      S Offline
                      S Offline
                      Schehaider_Aymen
                      wrote on last edited by
                      #13

                      May i use a 128 bit integer or double nd if yes how to do that so

                      "The Ultimate Limit Is Only Your Imagination."

                      C 1 Reply Last reply
                      0
                      • S Schehaider_Aymen

                        May i use a 128 bit integer or double nd if yes how to do that so

                        "The Ultimate Limit Is Only Your Imagination."

                        C Offline
                        C Offline
                        CPallini
                        wrote on last edited by
                        #14

                        Yes, if you have them. :)

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                        [My articles]

                        1 Reply Last reply
                        0
                        • S Schehaider_Aymen

                          ok so the best solution is to navigate into mthemticl splitting and mke the purpose by slices

                          "The Ultimate Limit Is Only Your Imagination."

                          N Offline
                          N Offline
                          norish
                          wrote on last edited by
                          #15

                          One solution is using Multiple Precision Number library like http://gmplib.org/[^]

                          S 1 Reply Last reply
                          0
                          • N norish

                            One solution is using Multiple Precision Number library like http://gmplib.org/[^]

                            S Offline
                            S Offline
                            Schehaider_Aymen
                            wrote on last edited by
                            #16

                            i alredy downloaded the GMP zip files but i had problems to use it in MVS 6.0 .. i m a newbie in such manipulations (integrating foreign files inti my project) . may be when my skills will be better i 'll try it :laugh:

                            "The Ultimate Limit Is Only Your Imagination."

                            L 1 Reply Last reply
                            0
                            • S Schehaider_Aymen

                              i alredy downloaded the GMP zip files but i had problems to use it in MVS 6.0 .. i m a newbie in such manipulations (integrating foreign files inti my project) . may be when my skills will be better i 'll try it :laugh:

                              "The Ultimate Limit Is Only Your Imagination."

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

                              I think you need to spend some more time reading about floating point number representations. A floating point (double) number allows you to store extremely large or extremely small values and anything in between, but at a cost of accuracy in these values. Thus they are no good for applications where numeric accuracy is important, e.g. anything to do with money. When you display such numbers on screen or printer you have various options for how you wish them to be represented on screen: in scientific 1.3456e-2, or decimal 0.013456 etc. If you want to use very large numbers with no loss of accuracy then you need to find a library or class (or write one) that can do it for you.

                              It's time for a new signature.

                              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