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

  • Home
  • SEARCH
  • 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 3624002
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:27:12+00:00 2026-05-18T23:27:12+00:00

Given an integer I would like to produce a unique floating point number in

  • 0

Given an integer I would like to produce a unique floating point number in the interval [0,1]. (this number will be used as id).
The problem I found with all functions I have thought about, is that they encounter duplicates before running out of integer values.
For example if f(a:int):float = 0.a then f(16000) = 0.16 and f(16001) = 0.16001. But since it is floating point, 0.16 and 0.16001 may be represented the same.
In other words, I need a function that produce not only unique numbers, but also numbers that are represented uniquely (at least forthe C++ integer domain).

I know the answer is dependent on the size of integer and floating point in a specific environment, but if you can give an example for specific sizes it will still be helpful.

  • 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-18T23:27:13+00:00Added an answer on May 18, 2026 at 11:27 pm

    As someone else pointed out you can simply cast an int to a float of the same size to get a unique float (with some post-filtering for NaN and -0 and Inf). However, that will not meet your requirement of being in [0,1]. In fact, you can use that relation to show that there are not enough floats in [0,1] to represent the set of integers. If you use double then the mantissa is easily large enough for a 32-bit int and an expression like I / (double)INT_MAX should be sufficient (obviously allow for unsignedness if you need to).

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

Sidebar

Related Questions

I would like to convert a given date and integer to a timestamp in
My object model is given below and would like your inputs on the number
Given a function R which produces true random 32 bit numbers, I would like
I would like a hint or much better a solution for this: I do
I would like to be able to output a timeline containing the number of
Would like some advice from this. I got a table where I want to
Given two integers a and b , how would I go about calculating the
I've got a System.Generic.Collections.List(Of MyCustomClass) type object. Given integer varaibles pagesize and pagenumber, how
Given an integer typedef: typedef unsigned int TYPE; or typedef unsigned long TYPE; I
You are given a 32-bit unsigned integer array with length up to 2 32

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.