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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:57:02+00:00 2026-06-13T14:57:02+00:00

How can I scale a set of values to fit a new range if

  • 0

How can I scale a set of values to fit a new range if they include negative numbers?

For example, I have a set of numbers (-10, -9, 1, 4, 10) which have to scaled to a range [0 1], such that -10 maps to 0, and 10 maps to 1.

The regular method for an arbitrary number ‘x’ would be:
(x – from_min) * (to_max – to_min) / (from_max – from_min) + to_min

but this does not work for negative numbers. Any help is appreciated. Thanks!!

  • 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-06-13T14:57:03+00:00Added an answer on June 13, 2026 at 2:57 pm

    I believe id does; in your example,

    from_min = -10,
    from_max = 10,
    to_max = 1,
    to_min = 0.
    

    This yields

    to_max - to_min = 1,
    from_max - from_min = 20;
    

    So using the formula

    x -> (x - from_min) * (to_max - to_min) / (from_max - from_min) + to_min
       = (x - from_min) * 1 / 20 + 0
       = (x - from_min) / 20
    

    yields

    -10 -> (-10 + 10) / 20 = 0 / 20,
    -9 -> (-9 + 10) / 20 = 1 / 20,
    1 -> (1 + 10) / 20 = 11 / 20,
    4 -> (4 + 10) / 20 = 14 / 20,
    10 -> (10 + 10) / 20 = 20 / 20,
    

    so all the resulting values are nonnegative. Furthermore, the original minimum -10 maps to to_min = 0 and the original maximum 10 maps to to_max = 1. If this doesn’t work in your implementation, check if you mixed up integral types and floating-point types.

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

Sidebar

Related Questions

I have a viewmodel which seems to be persisting the scale set in the
How can I discover the values of rotate/scale? For example, after I issue the
I am trying to make Custom RelativeLayout which can scale and scroll. Right now
How can I scale a random 3d model to fit in an opengl viewport?
I have been learning the mapreduce algorithm and how it can potentially scale to
The documentation states: Precision can range from 1 to 38. Scale can range from
I have used ImageView's before and understand the different scale types that can be
How can I have field dependency? Case 1: If boolean field call_me is set,
Can you set a jQuery slider to have a maximum value of 10,000 -
I have a d3 bar chart whose values range from 0-3. I would like

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.