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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:39:35+00:00 2026-06-01T19:39:35+00:00

I’ve been trying to find a Javascript version of a handy method I’d used

  • 0

I’ve been trying to find a Javascript version of a handy method I’d used (not written) a while ago in LPC, it was called dimval(), and it took this form:

NAME
     dimval() - returns values with a reduced increase in output
                as input values grow larger.

SYNOPSIS
     float dimval(float input, float max_input, float max_output,
                  float min_input, float min_output, float rate);

DESCRIPTION
     Returns (as a float) a value between min_output and max_output,
     with values increasing at a reduced rate as they move from
     min_input toward max_output.

     Input is the input value.

     Max_input is the maximum acceptable input. Any higher input
     value will be capped to this.

     Max_output is the maximum value returned.

     Min_input is the (optional) minimum input. Default is zero.

     Min_output is the (optional) minimum output. Default is zero.

     Rate determines how quickly the cost increases to achieve
     greater return values. Higher numbers are faster, lower numbers
     are slower.

I read this article, but it doesn’t seem to capture what I want (it looks much simpler for a start). I also read this SO question and… well I think this could work… but the Math is beyond me, to be honest. I understand the description above and how the parameters work together to produce the kind of result I want.

I’d greatly appreciate it if someone could provide a method which has the above constraints, in Javascript.

cheers!

EDIT: Sample outputs from original method.

  • eval return dimval(5.0, 100.0, 100.0, 0.0, 0.0, 1.0) => 22.360680
  • eval return dimval(10.0, 100.0, 100.0, 0.0, 0.0, 1.0) => 31.622776
  • eval return dimval(50.0, 100.0, 100.0, 0.0, 0.0, 1.0) => 70.710678

  • eval return dimval(10.0, 100.0, 100.0, 0.0, 0.0, 2.0) => 15.811388

  • eval return dimval(10.0, 100.0, 100.0, 0.0, 0.0, 10.0) => 3.162278

  • eval return dimval(200.0, 100.0, 100.0, 0.0, 0.0, 10.0) => 10.000000

  • eval return dimval(200.0, 100.0, 100.0, 0.0, 0.0, 1.0) => 100.000000

  • eval return dimval(1.0, 100.0, 100.0, 10.0, 0.0, 10.0) => 0.000000


Let me know if you want me to run any more samples.

  • 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-01T19:39:36+00:00Added an answer on June 1, 2026 at 7:39 pm

    Maybe something like this?

    function dimval(n, min_in, max_in, min_out, max_out, exponent) {
      // unscale input
      n -= min_in
      n /= max_in - min_in
    
      n = Math.pow(n, exponent)
    
      // scale output
      n *= max_out - min_out
      n += min_out
      return n
    }
    

    0 < exponent < 1 for fast increase first, then smaller increase, exponent > 1 for the reverse.

    Example:

    > dimval(0, 0, 1, 0, 100, 2)
    0
    > dimval(0.1, 0, 1, 0, 100, 2)
    1.0000000000000002
    > dimval(0.2, 0, 1, 0, 100, 2)
    4.000000000000001
    
    
    > dimval(0, 0, 1, 0, 100, 0.5)
    0
    > dimval(0.1, 0, 1, 0, 100, 0.5)
    31.622776601683793
    > dimval(0.2, 0, 1, 0, 100, 0.5)
    44.721359549995796
    > dimval(0.3, 0, 1, 0, 100, 0.5)
    54.77225575051661
    > dimval(0.4, 0, 1, 0, 100, 0.5)
    63.245553203367585
    > dimval(0.5, 0, 1, 0, 100, 0.5)
    70.71067811865476
    > dimval(0.6, 0, 1, 0, 100, 0.5)
    77.45966692414834
    > dimval(0.7, 0, 1, 0, 100, 0.5)
    83.66600265340756
    > dimval(0.8, 0, 1, 0, 100, 0.5)
    89.44271909999159
    > dimval(0.9, 0, 1, 0, 100, 0.5)
    94.86832980505137
    > dimval(1, 0, 1, 0, 100, 0.5)
    100
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I am trying to render a haml file in a javascript response like so:
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.