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 8070739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:29:54+00:00 2026-06-05T13:29:54+00:00

Background: I have an opc tag whose value is a 32 bit floating point

  • 0

Background:

I have an opc tag whose value is a 32 bit floating point number. The tag represents a running tally – so at some point the total will hit the max value and start again at 0. An additional bit of information about the tag is that it’s data type is single float but it’s value is always a whole number ( I didn’t create the tag so I’m not sure why float was chosen ).

In my application when a certain event is fired I record the current value of this running total and when another event is fired I take the current value of the total and then need to calculate the difference.

The only issue I have is that if the value were to be near max value when I take the initial reading, and then rollover to 0+ before I take the second reading I will end up with a negative value for the difference.

I’ve got this so far (it’s in c#):

    float diff (float a, float b) {
        if (b < a) {
            float f = float.MaxValue - a;
            return f + b;
        }
        return b - a;
    }

but this doesn’t work since unless a is huge, float.MaxValue – a == 0. Does anyone know how I might work this out?

  • 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-05T13:29:55+00:00Added an answer on June 5, 2026 at 1:29 pm

    Floats don’t overflow the same way integers do.

    If you add two floats that should add to a number larger than float.MaxValue, the result will be float.PositiveInfinity, not a large negative number as with signed integers or a small positive number as with unsigned integers.

    But before that happens, you will most likely run into a different problem: If you add a small number to a large number, the result might be the large number, unchanged. So, if the score always increases by some (relatively) small number, you will most likely find that, after a certain point, the score doesn’t change anymore.

    Because of all this, your “roll-over” will never happen and so maybe you don’t have to do anything. But even better solution would be to use an integer type to represent integers, thus avoiding all those pitfalls.

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

Sidebar

Related Questions

Background: I have several builds running on a Windows Server 2003 R2 machine via
Background: I have an object that has a number of properties that are other
Background: I have a short list of strings. The number of strings is not
Background: I have an application with an alternate entry point. It listenes for SMS
Background: I have some existing apps in the App Store and I have just
Background: I have a module which declares a number of instance methods module UsefulThings
Background I have a pair of functions I want to use to animate some
Background: I have a unit of optimised Delphi/BASM routines, mostly for heavy computations. Some
Background I have an installation of VisualSVN on a server. under this, I have
Background: I have a website where people can store transactions. As part of this

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.