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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:09:05+00:00 2026-05-30T10:09:05+00:00

Currently I am writing my thesis and I was confronted with a behavior of

  • 0

Currently I am writing my thesis and I was confronted with a behavior of .Net C# that I had never seen before. I am talking about an error in a calculation.
I implemented this formula:

1/2 * (Theta i-1 + Theta i) + Sum(Alph k, k=1, i-1)

This formula is applied to 4 objects. Theta is in all objects declared as float with the value 1,5708. Alpha is initialized with 0 and will be increased by each iteration.

First implmentation

    float alpha = 0;
    float value = 0;
    for (int sphereCount = 1; sphereCount < this.spheres.Count; sphereCount++)
    {
        value = (1/2) * (this.spheres[sphereCount - 1].Theta + this.spheres[sphereCount].Theta);
        alpha += value;
    }

With this version value is always 0.0!
So I changed it to:

Working implementaion

    float alpha = 0;
    float value = 0;
    for (int sphereCount = 1; sphereCount < this.spheres.Count; sphereCount++)
    {
        value =(this.spheres[sphereCount - 1].Theta + this.spheres[sphereCount].Theta) * 1/2;
        alpha += value;
    }

By removing the brackets around the 1/2 and placing it at the end of the calculation it worked.

WHY IS THAT SO???

It seems when you place 1/2 in brackets not depending on the position of 1/2 the result is 0.0. But also when i place (1/2) at the end it results in 0.0.
Does anyone here have an idea why?

  • 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-30T10:09:07+00:00Added an answer on May 30, 2026 at 10:09 am

    This

    (1 / 2)
    

    evaluates to 0 because it’s integer division. If you say

    (1 / 2f)
    

    or

    (1 / (float) 2)
    

    you’ll be fine because it forces float divsion. Or, even better, just write 0.5.

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

Sidebar

Related Questions

I'm currently writing some general purpose .net libraries that contain usual helper classes. For
I am currently writing my thesis about IT technologies etc. etc. and I have
I am currently writing a program using Weka that builds a model (using one
I'm currently writing a simple app that performs a series of requests to the
I am currently writing a simple IOS app that saves tasks into a table.
I'm currently writing a Powershell script that's used to select a user from Active
I'm currently writing my master thesis and I'm using TortoiseSVN to keep a backup
I'm writing my master thesis, which deals with AOP in .NET, among other things,
I am currently writing an application that needs to be able to select a
So I am currently writing a part of a program that takes user text

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.