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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:06:23+00:00 2026-05-29T07:06:23+00:00

I am writing an algorithm that divides a floating point number by 2. In

  • 0

I am writing an algorithm that divides a floating point number by 2.
In the case of the the numbers already being normalized (the exponent bits are > 0), I think the process is pretty straightforward. I think simply decreasing the exponent field by one and then sticking that value back in is a correct approach.

I am having trouble coming up with how to handle a floating point number already being denormalized (exponent bits are all 0’s).
I understand what a denormalized number is, and believe I generally understand what it means to divide them. I am running the algorithm I write through another program and here is one message I get that confuses me:

Passing the value 0x7fffff to the function returns 3fffff. The function is supposed to return 0x400000.

I don’t really understand what is going on here, and why this is supposed to return this specified value. Is there anybody that can try and explain this and why it is supposed to return this value?

My initial approach for handling a denormalized number was to right shift the fraction bits by one (dividing by 2), and that doesn’t seem to be the desired procedure.

Here is what I have:

unsigned float_half(unsigned uf) {

  unsigned exp = uf & (0x7F800000);
  unsigned sign = uf & (0x80000000);
  unsigned fract = uf & (0x007FFFFF);
  // Check for NaN or infinity
  if(exp == 0x7F800000) {
    return uf;
  }
  // Check for denormalized numbers
  if(exp == 0x00000000) {
    // Need to do something here, not really sure...

    return sign | exp | fract;
  } 
  // Check for exponent of 1 (going to a denormalized number changes things)
  if(exp == 0x00800000) {
    fract = (0x00FFFFFF & uf) >> 1;
    return fract | sign;
  }

  exp--;
  exp = exp & (0x7F800000);
  return sign | exp | fract;
}
  • 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-29T07:06:24+00:00Added an answer on May 29, 2026 at 7:06 am

    You are probably supposed to round the value in the denormalized case. For 0x7fffff you are cutting off the final 1 bit with the shift. It seems that you are expected to round the value up instead, for example like this:

    if(exp == 0x00000000) {
      fract = (0x00FFFFFF & uf) >> 1;
      if (0x00000001 & uf)
        fract++;
      return fract | sign;
    }
    

    If you are supposed to round up or down might also depend on the sign.

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

Sidebar

Related Questions

I'm writing an algorithm that iterates over a list of points, calculates the distance
I'm writing an implementation of the XXTEA encryption algorithm that works on streams, ie,
I'm writing a program that calculates the Jacobi algorithm. It's written in Objective-C since
I am writing a genetic algorithm that approximates an image with a polygon. While
I am writing a sliding window compression algorithm (LZ77) that searches for phrases in
I'm writing a Monte Carlo algorithm, in which at one point I need to
I'm writing a genetic algorithm that tries to chooses a set of the data
I'm writing an algorithm that detects clones in source code. E.g. if there is
Greetings code-gurus! I am writing an algorithm that connects, for instance node_A of Region_A
i'm working on image processing, and i'm writing a parallel algorithm that iterates over

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.