Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7889925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:13:19+00:00 2026-06-03T06:13:19+00:00

The next 2 lines adds the same amount to the same date, and the

  • 0

The next 2 lines adds the same amount to the same date, and the results date part is the same, but somehow the there’s difference in the time part!

(new DateTime(2000,1,3,18,0,0)).AddDays(4535);   
(new DateTime(2000,1,3,18,0,0)).AddMonths(149);

you’ll get a difference of 15 secs, and with both are at least roundable to days, I don’t know why this happend, but it happens only with AddDays, but not AddMonths (even with thousands of months added)


Edit 1

So I’ve tried to make a sample project, but no luck. If I run my main project, and put the sample lines into the watches, than I get 2 separate values, if I make a fresh start, the problem is not there. The project is 3.5, c#, vs2010, win7hp x64 (proj: x86). I’m trying to reproduce it also in a fresh small project, I’ll be writing back if I have it.

These are my results in the main project (copeid from watches!):

(new DateTime(2000, 1, 3, 18, 0, 0)).AddDays(4535).Ticks    
 634743432153600000 long

(new DateTime(2000, 1, 3, 18, 0, 0)).AddMonths(149).Ticks   
 634743432000000000 long

Edit 2

I’ve managed to narrow it down even more. We have a self-made component, panel base, we draw on it with directx. If I make that visible=false, than visible=true, than the error comes, before the visible=true (or show()), the calculation is correct. What in the world can be there, that the result gets something else of a formula where no variable is used. Culture is not affected in the component..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:13:21+00:00Added an answer on June 3, 2026 at 6:13 am

    This is a result of DirectX silently changing the floating-point calculation mode of the CPU to always use single precision. This is sometimes done for performance: using single precision can be quite a bit faster than using double precision. See the description of the FpuPreserve flag in the MSDN documentation for the DirectX CreateFlags enumeration.

    The reason others aren’t able to reproduce this is because they are not doing those DirectX calls.

    The argument to AddDays is a double. This value is multiplied by a scale factor to get the time in milliseconds. It is this calculation that produces the error.

    Consider:

    double value = 4535;
    int scale = 86400000;
    long milliseconds = (long) ((value * scale) + ((value >= 0.0) ? 0.5 : -0.5));
    long milliseconds2 = (long)((float)(value * scale) + ((value >= 0.0) ? 0.5 : -0.5));
    Console.WriteLine(milliseconds2 - milliseconds);
    

    The expression for milliseconds2 contains a cast to float, which mimics the effect of DirectX forcing single-precision calculations. This will print 15360, exactly the difference you find.

    By contrast, AddMonths takes an integer, and does not use any floating-point arithmetic. So the result is exact.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the next lines of code to transform Path object and draw
I´m studing the code of OpenCV, and I came across the next few lines:
I'm writing a daemon to monitor creation of new objects, which adds rows to
I asked a question earlier on this same project but I'm still having issues
I am writing a Firefox add-on that adds little icons next to all the
I've a string ( ifstream ) with next lines: foo foo+.. foo And, I'd
I need to clean my labelResult each time on textField Action, but on the
I wish to append dddd to the next line whenever I encounter = in
In vim , what command should be used if I wanna join next line
why the next python line is not a syntax error? If it is really

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.