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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:53:28+00:00 2026-06-05T16:53:28+00:00

I have a set of (floating point) numbers between x = 1 and y

  • 0

I have a set of (floating point) numbers between x = 1 and y = 9:

$numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9);

How can I compute a metric of the proximity, in the given interval, between number A and number B?


What I’ve Tried

If the amplitude (max - min) of the above set is 9 - 1 = 8 I am able to compute the relative value of any number using the formula (n - min) / (max - min), computing this for all values yields:

  • (1 - 1) / (9 - 1) = 0
  • (2 - 1) / (9 - 1) = 0.125
  • (3 - 1) / (9 - 1) = 0.25
  • (4 - 1) / (9 - 1) = 0.375
  • (5 - 1) / (9 - 1) = 0.5
  • (6 - 1) / (9 - 1) = 0.625
  • (7 - 1) / (9 - 1) = 0.75
  • (8 - 1) / (9 - 1) = 0.875
  • (9 - 1) / (9 - 1) = 1

Dividing the minimum relative value (between A and B) with the maximum relative value (also between A and B), seems to produce the kind of metric I’m looking for. Here are a few examples:

var_dump(min(0.875, 0.25) / max(0.875, 0.25));   // 0.286 between 8 and 3
var_dump(min(0.875, 0.375) / max(0.875, 0.375)); // 0.429 between 8 and 4
var_dump(min(0.875, 0.75) / max(0.875, 0.75));   // 0.857 between 8 and 7
var_dump(min(0.875, 0.875) / max(0.875, 0.875)); // 1 between 8 and 8
var_dump(min(0.25, 0.25) / max(0.25, 0.25));     // 1 between 3 and 3

The Problem

Whenever the minimum value of the set comes into play, the result will always be 0:

var_dump(min(0.875, 0) / max(0.875, 0));         // 0 between 8 and 1
var_dump(min(0.125, 0) / max(0.125, 0));         // 0 between 2 and 1
var_dump(min(0, 0) / max(0, 0));                 // 0 between 1 and 1 (ERR!)

Any ideas on how to solve this?

  • 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-05T16:53:30+00:00Added an answer on June 5, 2026 at 4:53 pm

    I was suggesting something like this:

    <?php
    
    function prox($a,$b)
    {
        return(abs($a-$b) / abs(1-9));
    }
    
    printf("%f\n", prox(1,2)); // 0.125000 
    printf("%f\n", prox(2,3)); // 0.125000
    printf("%f\n", prox(1,1)); // 0.000000
    printf("%f\n", prox(1,9)); // 1.000000
    

    The proximity between 1 and 2 is the same as 2 and 3. This seems to make sense.

    The largest proximity you’ll get is when the numbers you specify are the bounds of your predefined range.

    The smallest proximity you’ll get is when the numbers you specify are equal.

    If you want the opposite to be true (which I suppose better reflects proximity, you could do:

    <?php
    
    function prox($a,$b)
    {
        return(1 - (abs($a-$b) / abs(1-9)));
    }
    
    printf("%f\n", prox(1,2));
    printf("%f\n", prox(2,3));
    printf("%f\n", prox(1,1));
    printf("%f\n", prox(1,9));
    

    Which would output:

    0.875000
    0.875000
    1.000000
    0.000000
    

    Now, the same number produces 1 as you specified and the bounds produce 0 as they’re the least-proximate pair of values. Combinations like (1,2), (2,3), (3,4), etc. all produce the same value, as do combinations like (2,4), (3,5), (4,6), etc, etc.

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

Sidebar

Related Questions

I have a series with floating point numbers between 0 and 6. I wish
At work have a set of floating point values that I sort and compute
Imagine you have a large array of floating point numbers, of all kinds of
I have a floating point number that have more decimal digits, for example: float
Given a normalized floating point number f what is the next normalized floating point
I have some floating point numbers where I would like to indicate that that
I wish to round a floating point number to set precision and return the
Logically speaking, given the nature of floating point values, the maximum and minimum representable
Is it a good idea to use IEEE754 floating point NaN (not-a-number) for values
I am trying to convert an 80-bit extended precision floating point number (in a

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.