Rounding decimals to ruler scale (log, pow math?)

  • Context: Undergrad 
  • Thread starter Thread starter 1plus1is10
  • Start date Start date
  • Tags Tags
    Log Scale
Click For Summary

Discussion Overview

The discussion revolves around the mathematical methods for rounding decimal numbers (all less than 1) to the nearest fractions of 1/2, 1/4, 1/8, 1/16, and 1/32. Participants explore potential mathematical functions and algorithms to achieve this rounding.

Discussion Character

  • Exploratory
  • Mathematical reasoning

Main Points Raised

  • One participant expresses uncertainty about the mathematical approach to round down decimal values to specified fractions, suggesting the use of logarithmic or power functions.
  • Another participant seeks clarification on whether the inquiry is about mathematical functions or an algorithmic solution.
  • A different participant points out that rounding down to the nearest fraction means choosing one specific fraction (e.g., 1/2 or 1/4) rather than multiple fractions simultaneously.
  • A later reply describes a self-discovered method using the power function of 0.5 and logarithmic calculations to achieve the desired rounding, providing a code snippet as an example.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best method for rounding, as different approaches and interpretations of the problem are presented.

Contextual Notes

The discussion includes various assumptions about the rounding process and the mathematical functions involved, which remain unresolved. The clarity of the rounding criteria is also a point of contention.

1plus1is10
Messages
51
Reaction score
0
I have data (all less than 1) and I need to round down to the nearest 1/2, 1/4, 1/8, 1/16, and 1/32.
I have no idea how to do this mathematically, but I'm guessing I use log or pow functions.

For example:
0.81 = 0.5 or 1/2
0.33 = 0.25 or 1/4
0.18 = 0.125 or 1/8

Any help would be appreciated.
Thanks
 
Physics news on Phys.org
1plus1is10 said:
I have data (all less than 1) and I need to round down to the nearest 1/2, 1/4, 1/8, 1/16, and 1/32.
I have no idea how to do this mathematically, but I'm guessing I use log or pow functions.

For example:
0.81 = 0.5 or 1/2
0.33 = 0.25 or 1/4
0.18 = 0.125 or 1/8

Any help would be appreciated.
Thanks
Are you looking for the mathematical functions and symbols to use, or for an algorithmic solution?
 
1plus1is10 said:
I have data (all less than 1) and I need to round down to the nearest 1/2, 1/4, 1/8, 1/16, and 1/32.
What does this mean?
You can round down to the nearest 1/2 OR to the nearest 1/4 etc. You can't round to the nearest 1/16 AND 1/32, for example.
 
Sorry for not knowing how to phrase my question.
In the end, I figured it out myself after discovering that pow(0.5, x); gives fractions of the power of 2.

As for my data:
On a calculator, round up the result of: ln(x)/ln(0.5)
And then do a (0.5^y) exponent: 0.5^rounded_UP_result

In code, it is:
pow(0.5, ceil(log(x)/log(0.5)));

Thanks anyway.
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
4
Views
2K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 15 ·
Replies
15
Views
2K