logarithm

How to reverse fixed point binary log algorithm for fractional power of 2?

陌路散爱 提交于 2020-04-30 06:28:19
问题 I found a fast binary logarithm algorithm for fixed points in an answer to this question: Fast fixed point pow, log, exp and sqrt, based on an algorithm by Clay S. Turner. Is it possible to "reverse" this to calculate fractional powers of two? e.g: // log2(3) = 1.5849609375 log2fix(196608, 16) == 103872 pow2fix(103872, 16) == 196608 Here's the code from Dan Moulding: #include <errno.h> #include <stddef.h> #include "log2fix.h" int32_t log2fix (uint32_t x, size_t precision) { int32_t b = 1U <<

Get lognormal random number given log10 mean and log10 standard deviation

微笑、不失礼 提交于 2020-03-05 05:42:28
问题 I am given the log10 mean and log10 standard deviation of a log-normal distribution. I want to get a random number from this log-normal distribution. Can this be accomplished with numpy.random.lognormal, even though that function's inputs are the mean and standard of the underlying normal distribution (I do not have that)? Also, will the random number that I get back from the function be log10, natural log, or regular? 回答1: Wikipedia says that the parameters of lognormal distribution are

Logarithmic scale returns NaN

穿精又带淫゛_ 提交于 2020-02-23 09:09:09
问题 I have issues creating a logarithmic scale in d3. The scale works fine if it is set to linear. This works: var myLinScale = d3.scale.linear() .domain([0, 100]) .range([50, 1150]); console.log(myLinScale(71)); //output = 831 However, this doesn't work: var myLogScale = d3.scale.log() .domain([0, 100]) .range([50, 1150]); console.log(myLogScale(71)); //output = NaN What is wrong with the logarithmic scale? 回答1: New solution (using D3 v5.8) After more than 2 years this question finally has a D3

How to calculate the base 2 log of a matrix?

允我心安 提交于 2020-01-24 16:02:43
问题 The only function that I found that calculates the log of the matrix, and not of each component of the matrix, was scipy's logm() function, but it finds the log with base e, I need the base 2 log. 回答1: You can use the change-of-base formula to convert the base of the logarithm: log2(x) = logm(x) / logm(2) Mathematica StackExchange has some more in depth discussion of the math behind this: https://mathematica.stackexchange.com/a/92293 来源: https://stackoverflow.com/questions/54773370/how-to

How does using log10 correctly calculate the length of a integer? [closed]

浪尽此生 提交于 2020-01-22 14:39:46
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . int length = (int) floor( log10 (float) number ) + 1; My question is essentially a math question: WHY does taking the log10() of a number, flooring that number, adding 1, and then casting it into an int correctly calculate the length of number? I really want to know the deep mathematical explanation please! 回答1:

How does using log10 correctly calculate the length of a integer? [closed]

天大地大妈咪最大 提交于 2020-01-22 14:38:11
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . int length = (int) floor( log10 (float) number ) + 1; My question is essentially a math question: WHY does taking the log10() of a number, flooring that number, adding 1, and then casting it into an int correctly calculate the length of number? I really want to know the deep mathematical explanation please! 回答1:

How are logarithms programmed? [closed]

独自空忆成欢 提交于 2020-01-20 22:07:18
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . Are they just figured out using the same mechanism as a linear search or is the range narrowed down somehow, similar to a binary search. 回答1: The implementation of a function such as the natural logarithm in any

Logarithmic averaging preset function in excel - using ranges as input values

ε祈祈猫儿з 提交于 2020-01-16 23:41:13
问题 I need to add my own function for logarithmic averaging to excel but i'm not sure how to have a range of values as an input value or how to make count the number of values in a given range. I have a small amount of experience with programming. The formula i usually use in excel and am looking to implement as a pre-set function is the following: =10*LOG(SUM(10^('range of values'/10)/'number of values in the range')) Can anyone help me out? 回答1: You can try this, you may need to adjust to

Computing the floor of log₂(x) using only bitwise operators in C

隐身守侯 提交于 2020-01-13 12:23:16
问题 For homework, using C, I'm supposed to make a program that finds the log base 2 of a number greater than 0 using only the operators ! ~ & ^ | + << >> . I know that I'm supposed to shift right a number of times, but I don't know how to keep track of the number of times without having any loops or if s. I've been stuck on this question for days, so any help is appreciated. int ilog2(int x) { x = x | (x >> 1); x = x | (x >> 2); x = x | (x >> 4); x = x | (x >> 8); x = x | (x >> 16); } This is

Computing the floor of log₂(x) using only bitwise operators in C

本小妞迷上赌 提交于 2020-01-13 12:22:10
问题 For homework, using C, I'm supposed to make a program that finds the log base 2 of a number greater than 0 using only the operators ! ~ & ^ | + << >> . I know that I'm supposed to shift right a number of times, but I don't know how to keep track of the number of times without having any loops or if s. I've been stuck on this question for days, so any help is appreciated. int ilog2(int x) { x = x | (x >> 1); x = x | (x >> 2); x = x | (x >> 4); x = x | (x >> 8); x = x | (x >> 16); } This is