math

OpenMP GPU offloading math library?

一个人想着一个人 提交于 2020-07-19 18:06:38
问题 I am trying to offload code the GPU using OpenMP 4+ directives. I am using ubuntu 16.04 with GCC 7.2 and for general cases it is working fine. My problem comes when I am trying to offload a code that has a call to the sqrtf function that is defined in "math.h". The troubeling code is this: #pragma omp target teams distribute \ map(to:posx[:n],posy[:n],posz[:n]) \ map(from:frcx[:n],frcy[:n],frcz[:n]) for (int i = 0; i < n; i++) { frcx[i] = 0.0f; frcy[i] = 0.0f; frcz[i] = 0.0f; for (int j = 0;

concatenate binary of first N integers and return decimal value

久未见 提交于 2020-07-16 08:01:45
问题 Example, N = 3 The first N integers for value 3 is 1 , 2 , 3 Binary of 1 is 1 2 is 10 3 is 11 Concatenations of N=3 of binary values will be 11011 And the decimal value returned for the binary value 11011 is 27 The code I am using below only works for first integers N<=15 String input = ""; for(int i = 1;i<=n;i++) { input += (Integer.toBinaryString(i)); } return Integer.parseInt(input,2); For larger N numbers, any ideas on solving using modulo 10^9 + 7 (since concatenation is large) 回答1: Note

Javascript: Round by 100 [duplicate]

孤者浪人 提交于 2020-07-15 09:50:42
问题 This question already has answers here : Rounding to nearest 100 (7 answers) Closed 7 years ago . I'm trying to round a number the 100. Example: 1340 should become 1400 1301 should become 1400 and 298 should become 300 200 should stay 200 I know about Math.round but it doesn't round to the 100. How can I do that ? 回答1: Try this... function roundUp(value) { return (~~((value + 99) / 100) * 100); } That will round up to the next hundred - 101 will return 200. jsFiddle example - http://jsfiddle

How to create bezier curves for an arc with different start and end tangent slopes

大憨熊 提交于 2020-07-14 05:18:22
问题 I've been stuck on this for a week now i can't seem to solve it. I have an arc which i can convert to a series of bezier curves quite easily when the arc is flat: But i am struggling to work out how to find the bezier curves when the arc is a helix and the end tangents have different slopes. This is as far as i have gotten so far: As you can see each bezier curve has control points that are not on the right plane, and the start and end tangent (the red vectors in the second image) of the full

How to create bezier curves for an arc with different start and end tangent slopes

徘徊边缘 提交于 2020-07-14 05:14:33
问题 I've been stuck on this for a week now i can't seem to solve it. I have an arc which i can convert to a series of bezier curves quite easily when the arc is flat: But i am struggling to work out how to find the bezier curves when the arc is a helix and the end tangents have different slopes. This is as far as i have gotten so far: As you can see each bezier curve has control points that are not on the right plane, and the start and end tangent (the red vectors in the second image) of the full

What is the formula to get the number of passes in a shell sort?

我怕爱的太早我们不能终老 提交于 2020-07-10 08:58:05
问题 I'm referring to the original (Donald Shell's) algorithm. I'm trying to make a subjective sort based on shell sort. I already made all the logic, where it is exactly the same as the shell sort, but instead of the computer calculate what is greater, the user determines subjectively what is greater. But I would like to display a percentage or something to the user know how far in the sorting it is already. That's why I want to find a way to know it. What is the formula to get the number of

Use math operators on generic variables in a generic Java class

北城余情 提交于 2020-07-06 11:03:43
问题 I'm trying to write some code that will allow me to perform basic math operations on a "T extends Number" object instance. It needs to be able to handle any number type that is a subclass of Number . I know some of the types under Number have .add() methods built in, and some even have .multiply() methods. I need to be able to multiply two generic variables of any possible type. I've searched and searched and haven't been able to come up with a clear answer of any kind. public class Circle<T

Very fast approximate Logarithm (natural log) function in C++?

痞子三分冷 提交于 2020-07-05 02:52:07
问题 We find various tricks to replace std::sqrt (Timing Square Root) and some for std::exp (Using Faster Exponential Approximation) , but I find nothing to replace std::log . It's part of loops in my program and its called multiple times and while exp and sqrt were optimized, Intel VTune now suggest me to optimize std::log , after that it seems that only my design choices will be limiting. For now I use a 3rd order taylor approximation of ln(1+x) with x between -0.5 and +0.5 (90% of the case for

Calculate the LCM of two or three numbers in JavaScript

橙三吉。 提交于 2020-07-04 02:47:33
问题 I am using the following code to determine the GCD of two or three numbers: $('#calc').click(function(){ Math.GCD = function(numbers) { for (var i = 1 ; i < numbers.length ; i++){ if (numbers[i] || numbers[i] === 0) numbers[0] = twogcd(numbers[0], numbers[i]); } return numbers[0]; function twogcd(first, second) { if (first < 0) first = -first; if (second < 0) second = -second; if (second > first) {var temp = first; first = second; second = temp;} while (true) { first %= second; if (first == 0

math.cos(x) not returning correct value?

拜拜、爱过 提交于 2020-07-03 16:59:10
问题 I just started using python, and am having difficulty with a very basic program. I want to calculate the cosine of -20 degrees. It is my understanding that the default value is in radians, so this is the following code i tried: import math print math.cos(math.degrees(-20)) This outputs (-.7208...), where the answer is actually (.9397...). I'm sure this has a pretty basic solution but I've tried so many different things and it will not output the correct results. Thanks in advance! 回答1: Per