Questions tagged [absolute-value]

Absolute value is a mathematical function that returns the non-negative value of a number without regard to its sign.

Absolute value is a mathematical function that returns the non-negative value of a number without regard to its sign.

For example, both 7 and -7 will have an absolute value of 7.

Many programming languages include a function for absolute value in their standard math libraries, often named abs() or similar.

More information: http://en.wikipedia.org/wiki/Absolute_value

219 questions
3
votes
1 answer

PyTorch - Element-wise signed min/max?

I may be missing something obvious, but I can't find a way to compute this. Given two tensors, I want to keep the minimum elements in each one of them as well as the sign. I thought about sign_x = torch.sign(x) sign_y = torch.sign(y) min =…
fjrivasf
  • 33
  • 4
3
votes
5 answers

Using abs() in a list in Python

I am trying to create a list of integers and then scan it in order to find the minimum absolute value of the substractions of the elements of the list. I have created the list, but there is problem in the code which finds the minimum absolute value,…
Mike Johnson
  • 45
  • 1
  • 6
3
votes
1 answer

Difference Between two numbers without positive or negative in Ruby

I want to find the difference between two numbers (positive integers) without returning any positive or negative sign. Just like Diff(2,5) => 3 Diff(5,2) => 3. And Not (2 - 5) => -3
Suganya Selvarajan
  • 962
  • 1
  • 11
  • 33
3
votes
2 answers

how to get the absolute values in each element of array

I have some problem in converting the elements in the array to absolute values. Console.WriteLine("\nQ = {0}, difference = |{1} - {2}| = {3} ", a + 1, store[a], store2[a], Math.Abs(store3[a])); the store3 is a array. I already…
3
votes
1 answer

MS Excel 2010 - Calculation using Abs() stops working when placed in other VBA

I’ve written a macro that compares this month’s KPI figures with the equivalent figures from last month and then adds a symbol next to each figure to show whether performance is better, worse or the same. Performance is better if the number is…
gbavba
  • 116
  • 2
  • 9
3
votes
2 answers

Optimise byte operations CUDA

I am relatively new to Cuda and I am trying to write a kernel which calculates the sum of absolute differences between a query vector and a large database of vectors. The elements of both must be 8 bit unsigned ints. I've based my kernel off nvidias…
user3678912
  • 69
  • 2
  • 4
3
votes
3 answers

Is there a fast fabsf replacement for "float" in C++?

I'm just doing some benchmarking and found out that fabsf() is often like 10x slower than fabs(). So I disassembled it and it turns out the double version is using fabs instruction, float version is not. Can this be improved? This is faster, but not…
Vojtěch Melda Meluzín
  • 1,117
  • 3
  • 11
  • 22
3
votes
2 answers

How to simplify Assembly Translation Shift Right by 32 Xor Absolute Number And Value

I don't know the original code but I don't believe it's this complicated with right shift's and abs. Here is how the decompiled IDA PRO code renamed looks like char Ship; //Could be 0-7 (8 is reversed for special purpose) char NewShip = 1; //Could…
user3435580
  • 566
  • 1
  • 4
  • 15
3
votes
2 answers

Faster implementation of Math.abs() by bit-manipulation

The normal implementation of Math.abs(x) (as implemented by Oracle) is given by public static double abs(double a) { return (a <= 0.0D) ? 0.0D - a : a; } Isn't it faster to just set the one bit coding for the sign of the number to zero (or…
Tim Kuipers
  • 1,705
  • 2
  • 16
  • 26
3
votes
4 answers

Speeding up double absolute value in C++

I'm profiling my code and optimized everything I could, coming down to a function which looks something like this: double func(double a, double b, double c, double d, int i){ if(i > 10 && a > b || i < 11 && a < b) return abs(a-b)/c; …
sashkello
  • 17,306
  • 24
  • 81
  • 109
2
votes
2 answers

How can I find the difference between 2 values in C#?

I am working with an Oscillator that fluctuates between 10.000000 and -10.000000 The value changes say every 5 minutes. I want to find the difference between the current value and the value of 5 minutes ago. Here is my logic. 1 bar ago (1BA)=…
r2kTrader
2
votes
2 answers

Can I create a union with formal parameter passed to a function in C++?

The function below calculates absolute value of 32-bit floating point value: __forceinline static float Abs(float x) { union { float x; int a; } u; //u.x = x; u.a &= 0x7FFFFFFF; return u.x; } union u declared in…
Vadim
  • 1,223
  • 2
  • 17
  • 26
2
votes
3 answers

C simd _m128 fabs

How to make fabs() for __m128 vector ? Does I have to use sign bits to multiply the original vector by 1.0f/-1.0f ? Didn't find any instruction set to do it. I don't want __m256 or 512. I'm searching for __m128 data type
K V
  • 61
  • 8
2
votes
3 answers

How do you programatically position an object in Silverlight?

In Flash this question is answered really easy because you can set the X and Y coordinates of an object: newxpos = object._x; newypos = object._y; How do you do the same in Silverlight?
Ry.
  • 173
  • 3
  • 13
2
votes
0 answers

Equality with absolute value

Solving the equality with absolute value I use sympy with nonlinsolve function. For example, I solve |a + b| = a + b as follows from sympy import nonlinsolve, symbols, Abs a,b = symbols('a, b', real = True) eqn = [Abs(a + b) - (a +…
Artem
  • 3,304
  • 3
  • 18
  • 41