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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:54:59+00:00 2026-05-26T06:54:59+00:00

This is so simple I can’t believe I’m having so much trouble with it.

  • 0

This is so simple I can’t believe I’m having so much trouble with it.

For an analogy to what I’m after imagine a two handed clock face, where instead of 12 hours the time was between 0 and 1.

The two hands can point in any direction, provided there values are 0 to 1, for example one pointing upwards and the other diagonally down and to the left would be 0 and 0.625.

I need a c++\c# function that given the position both hands and a bool representing if the larger or smaller segment between the hands is desired returns the position half way between both hands.

For example “0.2, 0.8, false” would refer to the smaller segment between both hands and the answer would be 0.

float func(float a, float b, bool side)
{
    return 0f;
}

In many cases the calculation would be simply “(a + b) * 0.5”, however when crossing 0 as in the above example it is not. It’s also not as simple as putting a single branch in like an “if”. It seems there should be a solution far more elegant than ones I’ve tried.

edit: I’ve finally solved it myself, see the code below, additionally after various others attempted the peoblem a far more elegent solution was found.

float segment_size(float a, float b, bool side)
{
    float larger, smaller, c, d_smaller, d_larger;
    if (a > b)
    {
        smaller = b;
        larger = a;
    }
    else
    {
        smaller = a;
        larger = b;
    }
    c = larger - smaller;
    if (c > 0.5) {d_larger = c; d_smaller = 1 - c;} else {d_larger = 1 - c; d_smaller = c;}
    return side ? d_larger : d_smaller;
}

float func(float a, float b, bool side)
{
    float larger, smaller, c;
    if(a > b)
    {
        smaller = b;
        larger = a;
    }
    else
    {
        smaller = a;
        larger = b;
    }
    c = larger - smaller;
    float outf = 0, out1 = (float)((a + b) * 0.5),
    out3 = (float)(smaller - (segment_size(a, b, false) * 0.5)),
    out4 = (float)((smaller + larger) * 0.5);
    if(out4 > 0.5) {out4 -= 0.5f;} else {out4 += 0.5f;}
    if ((side == false && c <= 0.5) || (side == true && c > 0.5)) {outf = out1;}
    if (side == false && c > 0.5) {outf = out3;}
    if (side == true && c <= 0.5) {outf = out4;}
    if(outf < 0) {outf += 1;} if(outf >= 1) {outf -= 1;}
    return outf;
}
  • 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-05-26T06:55:00+00:00Added an answer on May 26, 2026 at 6:55 am

    Yeah, so I got it very wrong the first time around (calculated the length of the segment instead of its halving point), and also the second time around (was kind of dodgy, so ended up deleting the answer), but bear with me.

    The solution lies in the fact we’re talking about a circle here. So if we have one halving point, we can get the other by adding half of the circumference of the circle (0.5) to that.

    suppose 0<=a<1, 0<=b<1

    if(a>b) {
       hi=a;
       lo=b;
    } else {
       hi=b;
       lo=a;
    }
    
    d=hi-lo;
    
    if( (d>0.5 && greater_segment_needed) || (d<=0.5 && !greater_segment_needed)) { 
        result=lo+d/2
    } else
        result=lo+d/2+0.5; //the marvels of geometry
    }
    
    if(result>1) result-=1; //handling possible overflow
    return result;
    

    I’m pretty sure this works. And yeah, I edited it again >_>

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

Sidebar

Related Questions

I imagine this is simple - but I can't find the right combination of
A simple question i can't figure out. I'm having this simple sendmail script in
I can't believe how something this simple can seem so hard to do in
I have this really simple trouble I can't seem to overcome. I'm trying to
After searching, can't find the answer to this simple question. Yes, I read the
I have this simple example I can't seems to get working : MERGE INTO
This seems simple but I can't figure it out. I receive post data in
I can not get to make this comparison in this simple code error ..
Can anybody help me with this simple code?? #include <iostream> using namespace std; void
Can't seem to achieve this simple functionality! All I want is to clear a

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.