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. Precision Problem

Precision Problem

Scheduled Pinned Locked Moved C / C++ / MFC
c++csshelpquestion
2 Posts 2 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.
  • E Offline
    E Offline
    emrosa
    wrote on last edited by
    #1

    Hi...I'm working with trigonometric functions in visual C++ V6.0. I have this program that converts degrees to radians, applies some direct trigonometric functions, and then some inverse functions. The inverse function I'm using is the ATAN2(y,x). I have checked the function and it uses the definition of pi=3.141592653589793116E00. The examples given in the MSN documentation uses pi=3.1415926535 giving the correct results. Then, I was using the last definition of pi to convert degrees to radians and viceversa, but using also the atan2(y,x) function, and I'm getting that: cos(90. degrees)=-3.4914833611094e-15 Then, because the definition of pi is different in the conversion and the function, I have decided to make it uniform, as I cannot change the definition of pi in the atan2() function, I decided to change the definition of pi used for the conversions, however, I ave got the following: cos(90. degrees)=-6.1230317691119e-017 Which is less than the previous result, but still is not correct. Is there anyway to avoid this situation? Thanks, Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311

    J 1 Reply Last reply
    0
    • E emrosa

      Hi...I'm working with trigonometric functions in visual C++ V6.0. I have this program that converts degrees to radians, applies some direct trigonometric functions, and then some inverse functions. The inverse function I'm using is the ATAN2(y,x). I have checked the function and it uses the definition of pi=3.141592653589793116E00. The examples given in the MSN documentation uses pi=3.1415926535 giving the correct results. Then, I was using the last definition of pi to convert degrees to radians and viceversa, but using also the atan2(y,x) function, and I'm getting that: cos(90. degrees)=-3.4914833611094e-15 Then, because the definition of pi is different in the conversion and the function, I have decided to make it uniform, as I cannot change the definition of pi in the atan2() function, I decided to change the definition of pi used for the conversions, however, I ave got the following: cos(90. degrees)=-6.1230317691119e-017 Which is less than the previous result, but still is not correct. Is there anyway to avoid this situation? Thanks, Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311

      J Offline
      J Offline
      Jambolo
      wrote on last edited by
      #2

      emrosa wrote: cos(90. degrees)=-3.4914833611094e-15 cos(90. degrees)=-6.1230317691119e-017 You should never expect to get exactly 0. Floating-point numbers and operations are not exact. It seems to me that -0.0000000000000034914833611094 and -0.000000000000000061230317691119 are pretty close to 0.

      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