logarithm

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

走远了吗. 提交于 2020-01-13 12:22:06
问题 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

Logarithmic y axis with morris.js

房东的猫 提交于 2020-01-13 05:09:07
问题 I'm trying to get a logarithmic scale for the y-axis of a morris.js line chart. http://www.oesmith.co.uk/morris.js/lines.html I already tried playing with the yLabelFormat option, but it's not what I need. Any hint is appreciated. If there is no way of doing this with morris.js, you can suggest another lightweight javascript library to make simple line charts with logarithmic scale. 回答1: You can extend Morris and modify the transY function to do the logarithmic scale. I also added the

Displaying minor logarithmic ticks in x-axis in R

谁说我不能喝 提交于 2020-01-11 18:50:07
问题 I have a normal distribution plot and a histogram plot with x axis in log scale displaying 0, 10^0, 10^1 ... I want to include minor ticks between the major ones. Actually I was able to change the major ticks format from 1, 2, 3 and so on to 10^0, 10^1, 10^2, 10^3 using the solution given to me in my previous question. I used the following code for the major ticks : major.ticks <- axTicks(1) labels <- sapply(major.ticks,function(i) as.expression(bquote(10^ .(i))) ) axis(1,at=major.ticks

Displaying minor logarithmic ticks in x-axis in R

做~自己de王妃 提交于 2020-01-11 18:49:13
问题 I have a normal distribution plot and a histogram plot with x axis in log scale displaying 0, 10^0, 10^1 ... I want to include minor ticks between the major ones. Actually I was able to change the major ticks format from 1, 2, 3 and so on to 10^0, 10^1, 10^2, 10^3 using the solution given to me in my previous question. I used the following code for the major ticks : major.ticks <- axTicks(1) labels <- sapply(major.ticks,function(i) as.expression(bquote(10^ .(i))) ) axis(1,at=major.ticks

Calculating Logarithms with Python

我怕爱的太早我们不能终老 提交于 2020-01-11 12:08:37
问题 I am trying to calculate logarithms using the math module of python (math.log(x,[base]) , however when I use float(raw_input) for the x and base values, it gives me the error, ZeroDivisionError: float division by zero . x = 9.0 base = 3.0 回答1: Nonsense, it works perfectly well >>> import math >>> x=float(raw_input()) 9.0 >>> base=float(raw_input()) 3.0 >>> math.log(x, base) 2.0 Why don't you show us exactly how you reproduce the problem? wim is quite correct - a base of 1 will give that error

Why log(1000)/log(10) isn't the same as log10(1000)?

自古美人都是妖i 提交于 2020-01-11 10:05:48
问题 Today, I came across quite strange problem. I needed to calculate string length of a number, so I came up with this solution // say the number is 1000 (int)(log(1000)/log(10)) + 1 This is based on mathematical formula log 10 x = log n x/log n 10 (explained here) But I found out, that in C, (int)(log(1000)/log(10)) + 1 is NOT equal to (int) log10(1000) + 1 but it should be. I even tried the same thing in Java with this code (int) (Math.log(1000) / Math.log(10)) + 1 (int) Math.log10(1000) + 1

How to find antilog for a number using java programm?

北城以北 提交于 2020-01-11 07:32:16
问题 can someone please tell me How to find antilog for a number using java program? i am new to this java Math.log(10) gives the log value. now I want to take this output and verify using antilog that program is giving right value.please help me. 回答1: mathematically: e^(ln x) = x in java: Math.pow(Math.E, (Math.log(x)) == x; //equals true 回答2: You can use Logarithm class in Java to calculate log and antilog. More on this is provided here. 来源: https://stackoverflow.com/questions/18209676/how-to

Time Complexity of a loop that integer divides the loop counter by a constant

吃可爱长大的小学妹 提交于 2020-01-10 05:33:04
问题 I'm trying to calculate the time complexity of a simple algorithm in big O notation, but one part of it is seriously boggling my mind. Here is a simplified version of the algorithm: int a=n while(a>0) { //for loop with time complexity n^3 a = a/8 } In this instance, it's integer division, so the while loop will terminate after a's value drops below 8. I'm not sure how to express this in terms of n. I'd also like to know how to tackle future calculations like this, where the number of loops

Round up to nearest power of 10

和自甴很熟 提交于 2020-01-04 01:49:12
问题 I'm trying to figure out how to round up a number (greater than 0) to the nearest power of 10. Examples: roundUp(23.4) = 100 roundUp(2.34) = 10 roundUp(.234) = 1 roundUp(0.0234) = 0.1 roundUp(0.00234) = 0.01 For numbers greater than 1, I believe this works: 10^(ceil(log10(x))) But for numbers between 0 and 1, I'm not sure how to arrive at the answer. 回答1: Oops. I didn't realize the function actually DOES work for numbers between 0 & 1. It was a brain fart that I saw a negative number for

Python, Seaborn: Logarithmic Swarmplot has unexpected gaps in the swarm

别说谁变了你拦得住时间么 提交于 2020-01-03 04:48:13
问题 Let's look at a swarmplot, made with Python 3.5 and Seaborn on some data (which is stored in a pandas dataframe df with column lables stored in another class. This does not matter for now, just look at the plot): ax = sns.swarmplot(x=self.dte.label_temperature, y=self.dte.label_current, hue=self.dte.label_voltage, data = df) Now the data is more readable if plotted in log scale on the y-axis because it goes over some decades. So let's change the scaling to logarithmic: ax.set_yscale("log") ax