+ Reply to Thread
Results 1 to 7 of 7

Roundoff error?

  1. #1
    Registered User
    Join Date
    04-14-2014
    Location
    Laguna Niguel, CA
    MS-Off Ver
    Version 2404
    Posts
    44

    Roundoff error?

    I have an expression:
    =sin(radians(90))*cos(radians(90))
    The result is -6.1257E-17.
    How do I get this to be zero?
    Thank you

  2. #2
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.96 for Mac MS 365
    Posts
    8,690

    Re: Roundoff error?

    deleted, irrelevant to the issue.
    Last edited by Sam Capricci; 10-01-2022 at 08:37 PM.
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: Roundoff error?

    What precision to you expect from your calculations? Something like =ROUND(formula,expected precision) should work, but you need some idea as the programmer how close to 0 ought to be seen as exactly 0.

    edit to add: The other question might be to understand exactly what problem you are experiencing when Excel returns x.xxE-17 type of numbers. Perhaps a more appropriate strategy could be discussed if we better understood the exact nature of the problem this presents.
    Last edited by MrShorty; 10-01-2022 at 02:33 PM.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,459

    Re: Roundoff error?

    If you format the result as Number, it will display 0.00. If you increase the decimals, it will, eventually, show 0.0000000000000000612323400. That is, 6.12323E-17 (a positive number).
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    04-14-2014
    Location
    Laguna Niguel, CA
    MS-Off Ver
    Version 2404
    Posts
    44
    Quote Originally Posted by MrShorty View Post
    What precision to you expect from your calculations? Something like =ROUND(formula,expected precision) should work, but you need some idea as the programmer how close to 0 ought to be seen as exactly 0.

    edit to add: The other question might be to understand exactly what problem you are experiencing when Excel returns x.xxE-17 type of numbers. Perhaps a more appropriate strategy could be discussed if we better understood the exact nature of the problem this presents.
    It would be helpful to me to know why Excel gives this result when my simple calculator (and my own brain) quickly returns a value of zero.

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: Roundoff error?

    How deep down the "floating point arithmetic and error" rabbit hole do you want to go? The short answer is that computers (including Excel) are limited in how many digits they can use to "approximate" numbers and calculations. Because the calculation can never be exact (unless you are using a programming language like MathCad that knows to force cos(pi/2) to be exactly 0), calculations like this frequently return a result that is a few bits off of the theoretically correct calculation. We as programmers cannot change how computers perform arithmetic, so we just have to figure out how we are going to account for floating point anomalies.

    If you want a deeper dive, I suggest messaging user curiouscat408 and see if he will chime in. He seems much more experienced tracing floating point errors through the entire arithmetic sequence.

    If you want to do a deep dive into floating point arithmetic, this might be a good start: https://docs.oracle.com/cd/E19957-01..._goldberg.html

  7. #7
    Valued Forum Contributor
    Join Date
    07-13-2021
    Location
    California, USA
    MS-Off Ver
    2010
    Posts
    513

    Re: Roundoff error?

    There are two possible and equally plausible explanations. I think MrShorty already covered them adequately.

    The first is: Bill's calculator might store numbers internally with much more precision than it displays. Consequently, displayed calculations might round differently. That is certainly true of the Windows (Win7) Calculator application.

    The second is: The calculator might make a special case of COS(RADIANS(90)) (*) and return exactly zero. Unfortunately, Excel does not do that. And as I explained in post #5 in another thread (click here), the series sum to approximate COS happens to return 6.1257422745431001E-17 (17 sig digit precision).

    (* Or COS(90) in deg mode. Bill does not say exactly what he enters on the calculator.)

    Aside.... Since both SIN(RADIANS(90)) and COS(RADIANS(90)) return positive values in Excel, I have no idea how =sin(radians(90))*cos(radians(90)) returns -6.1257E-17 (sic), a negative number. I presume that Bill mistyped something.
    Last edited by curiouscat408; 10-02-2022 at 12:02 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] roundoff
    By keby1nko in forum Excel General
    Replies: 4
    Last Post: 12-15-2014, 04:58 AM
  2. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 AM
  3. Error 75 File/Path access error, sometimes Error 1004
    By smokebreak in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-16-2011, 02:35 PM
  4. to roundoff the digits for display in textbox of userform
    By taniks in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-21-2009, 10:54 AM
  5. Error Handling - On Error GoTo doesn't trap error successfully
    By David in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2006, 02:10 PM
  6. What is the roundoff error in the subtraction function?
    By Bill Owens in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-31-2005, 08:30 PM
  7. roundoff when converting text to numbers
    By Jack in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-29-2005, 10:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1