logarithm

Fast fixed point pow, log, exp and sqrt

余生长醉 提交于 2019-11-27 17:24:42
I've got a fixed point class (10.22) and I have a need of a pow, a sqrt, an exp and a log function. Alas I have no idea where to even start on this. Can anyone provide me with some links to useful articles or, better yet, provide me with some code? I'm assuming that once I have an exp function then it becomes relatively easy to implement pow and sqrt as they just become. pow( x, y ) => exp( y * log( x ) ) sqrt( x ) => pow( x, 0.5 ) Its just those exp and log functions that I'm finding difficult (as though I remember a few of my log rules, I can't remember much else about them). Presumably,

Logarithmic slider

匆匆过客 提交于 2019-11-27 17:01:10
I have a slider with values ranging from 0 to 100. I want to map them to a range from 100 to 10,000,000. I've seen some functions scattered around the net but they're all in C++. I need it in Javascript. Any ideas? You can use a function like this: function logslider(position) { // position will be between 0 and 100 var minp = 0; var maxp = 100; // The result should be between 100 an 10000000 var minv = Math.log(100); var maxv = Math.log(10000000); // calculate adjustment factor var scale = (maxv-minv) / (maxp-minp); return Math.exp(minv + scale*(position-minp)); } The resulting values match a

How do you calculate log base 2 in Java for integers?

孤街浪徒 提交于 2019-11-27 16:45:38
I use the following function to calculate log base 2 for integers: public static int log2(int n){ if(n <= 0) throw new IllegalArgumentException(); return 31 - Integer.numberOfLeadingZeros(n); } Does it have optimal performance? Does someone know ready J2SE API function for that purpose? UPD1 Surprisingly for me, float point arithmetics appears to be faster than integer arithmetics. UPD2 Due to comments I will conduct more detailed investigation. UPD3 My integer arithmetic function is 10 times faster than Math.log(n)/Math.log(2). If you are thinking about using floating-point to help with

Custom logarithmic axis scaling in matplotlib

六月ゝ 毕业季﹏ 提交于 2019-11-27 16:17:55
I'm trying to scale the x axis of a plot with math.log(1+x) instead of the usual 'log' scale option, and I've looked over some of the custom scaling examples but I can't get mine to work! Here's my MWE: import matplotlib.pyplot as plt import numpy as np import math from matplotlib.ticker import FormatStrFormatter from matplotlib import scale as mscale from matplotlib import transforms as mtransforms class CustomScale(mscale.ScaleBase): name = 'custom' def __init__(self, axis, **kwargs): mscale.ScaleBase.__init__(self) self.thresh = None #thresh def get_transform(self): return self

What is the best data structure for storing a set of four (or more) values?

冷暖自知 提交于 2019-11-27 14:13:43
Say I have the following variables and its corresponding values which represents a record . name = 'abc' age = 23 weight = 60 height = 174 Please note that the value could be of different types ( string , integer , float , reference-to-any-other-object, etc). There will be many records (at least >100,000). Each and every record will be unique when all these four variables (actually its values ) are put together. In other words, there exists no record with all 4 values are the same. I am trying to find an efficient data structure in Python which will allow me to (store and) retrieve records

How to find a binary logarithm very fast? (O(1) at best)

亡梦爱人 提交于 2019-11-27 13:55:19
问题 Is there any very fast method to find a binary logarithm of an integer number? For example, given a number x=52656145834278593348959013841835216159447547700274555627155488768 such algorithm must find y=log(x,2) which is 215. x is always a power of 2. The problem seems to be really simple. All what is required is to find the position of the most significant 1 bit. There is a well-known method FloorLog, but it is not very fast especially for the very long multi-words integers. What is the

What is the complexity of the log function?

此生再无相见时 提交于 2019-11-27 11:11:48
问题 What is the complexity of the log base 10 function? 回答1: This really depends on the domain of what values you want to compute a logarithm of. For IEEE doubles, many processors can take logarithms in a single assembly instruction; x86 has the FYL2X and FYL2XP1 instructions, for example. Although typically instructions like these will only take the logarithm in some fixed base, they can be used to take logarithms in arbitrary bases by using the fact that log a b = log c b / log c a by simply

Convert Linear scale to Logarithmic

三世轮回 提交于 2019-11-27 11:02:54
I have a linear scale that ranges form 0.1 to 10 with increments of change at 0.1: |----------[]----------| 0.1 5.0 10 However, the output really needs to be: |----------[]----------| 0.1 1.0 10 (logarithmic scale) I'm trying to figure out the formula needed to convert the 5 (for example) to 1.0. Consequently, if the dial was shifted halfway between 1.0 and 10 (real value on linear scale being 7.5), what would the resulting logarithmic value be? Been thinking about this for hours, but I have not worked with this type of math in quite a few years, so I am really lost. I understand the basic

How to expand and compute log(a + b)? [closed]

柔情痞子 提交于 2019-11-27 10:41:23
问题 I would like to know the complete expansion of log(a + b) . For example log(a * b) = log(a) + log(b); log(a / b) = log(a) - log(b); Similar to this, is there any expansion for log(a + b)? 回答1: In general, one doesn't expand out log(a + b) ; you just deal with it as is. That said, there are occasionally circumstances where it makes sense to use the following identity: log(a + b) = log(a * (1 + b/a)) = log a + log(1 + b/a) (In fact, this identity is often used when implementing log in math

Logarithm for BigInteger

可紊 提交于 2019-11-27 09:01:43
I have a BigInteger number, for example beyond 2 64 . Now i want to calculate the logarithm of that BigInteger number, but the method BigInteger.log() does not exist. How do I calculate the (natural) logarithm of my large BigInteger value? If you want to support arbitrarily big integers, it's not safe to just do Math.log(bigInteger.doubleValue()); because this would fail if the argument exceeds the double range (about 2^1024 or 10^308, i.e. more than 300 decimal digits ). Here's my own class that provides the methods double logBigInteger(BigInteger val); double logBigDecimal(BigDecimal val);