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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:27:50+00:00 2026-05-30T14:27:50+00:00

I want to create an array containing values from 0 to 1 with interval

  • 0

I want to create an array containing values from 0 to 1 with interval of 0.1. I can use:

float[] myArray = new float[10];
float increment = 0.1;
for(i = 0; i < 10; i++)
{
   myArray[i] = increment;
   increment += 0.1;
}

I was wondering whether there is a function like Enumerable.Range that permits to specify also the increment interval.

  • 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-30T14:27:51+00:00Added an answer on May 30, 2026 at 2:27 pm

    An interesting fact is that every answer posted so far has fixed the bug in your proposed code, but only one has called out that they’ve done so.

    Binary floating point numbers have representation error when dealing with any quantity that is not a fraction of an exact power of two. (“3.0/4.0” is a representable fraction because the bottom is a power of two; “1.0/10.0” is not.)

    Therefore, when you say:

    for(i = 0; i < 10; i++) 
    {
        myArray[i] = increment;    
        increment += 0.1; 
    } 
    

    You are not actually incrementing “increment” by 1.0/10.0. You are incrementing it by the closest representable fraction that has an exact power of two on the bottom. So in fact this is equivalent to:

    for(i = 0; i < 10; i++) 
    {
        myArray[i] = increment;    
        increment += (exactly_one_tenth + small_representation_error);
    } 
    

    So, what is the value of the tenth increment? Clearly it is 10 * (exactly_one_tenth + small_representation_error) which is obviously equal to exactly_one + 10 * small_representation_error. You have multiplied the size of the representation error by ten.

    Any time you repeatedly add together two floating point numbers, each subsequent addition increases the total representation error of the sum slightly and that adds up, literally, to a potentially large error. In some cases where you are summing thousands or millions of small numbers the error can become far larger than the actual total.

    The far better solution is to do what everyone else has done. Recompute the fraction from integers every time. That way each result gets its own small representation error; it does not accumulate the representation errors of previously computed results.

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

Sidebar

Related Questions

I've created a mutable array containing NSRect values. I want to check whether the
I want to create an array with a message. $myArray = array('my message'); But
Imagine that I want to create an array from another array like this: $array
Given an array containing other nested arrays, I want to create an array containing
I want to create a dictionary containing array and send it to GAE using
I have an array returned from a web service containing byte values (non binary
I want to create an array containing all the Pushpin objects I am dealing
I have a numpy array containing: [1, 2, 3] I want to create an
I want to create an array/list of strings of the Comma seperated strings (file
I want to create an array holding a function f(x,y,z) . If it were

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.