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
1
vote
2 answers

float to integer in python

If I want to convert a float to an integer in Python, what function do I use? The problem is that I have to use a variable passed through the function math.fabs (Absolute Value) as an index for a list, so it has to be an int, while the function…
user973057
  • 23
  • 3
1
vote
1 answer

compare absolute value with double value present in table using PostgreSQL

select id from records where (mean_logratio = -4.81) -4.810215473175049 value is present in the table which supposed to be fetched -4.810215473175049 only exact value is accepted not absolute value, in search query for = and != condition for…
1
vote
0 answers

How can I insert this objective function with these constraints on gurobi using java?

obj function: min |Xij*Pij - Xik*Pik| (i=1..10, j=1..4, k=5..8) constraints: Xij\<=Tij ∀i,j; ΣXij*Cij\<=Bi ∀i; ΣXij*Cij\>=0.02ΣBi ∀j; ΣXij*Pij\>=S ∀i,j; I try this but it doesn't work(Infeasible model): obj funct: GRBVar w =…
1
vote
2 answers

How can I use the python map() function to handle a list of tuples?

I currently have two lists and a working script that when given an element from list_a, finds all datetimes from list_b that are within 30 minutes. The community helped me with it in a previous question. I replaced one of the lists with a list of…
Blumie
  • 45
  • 1
  • 5
1
vote
0 answers

Refactor extended namespace std

I have a large project where namespace std is extended with std::abs for a custom type like in the following example. struct A { int a; }; namespace std { template auto abs(A const& x) -> A { return…
Henk
  • 826
  • 3
  • 14
1
vote
1 answer

Mathematically find the value that is closest to 0

Is there a way to determine mathematically if a value is closer to 0 than another? For example closerToZero(-2, 3) would return -2. I tried by removing the sign and then compared the values for the minimum, but I would then be assigning the…
1
vote
1 answer

Make all numbers in array Absolute value in Javascript

I'm trying to make all values in the below array absolute, after trying several methods the results that appears is 5 the first element in the array. the below is the code given: describe('absoluteValueArray', () => { it('Gets multiple absolute…
Nad.E.S
  • 49
  • 1
  • 7
1
vote
1 answer

Find Absolute in AVX

In one of the solution, he/she found abs(inp) for AVX vectors as, __m256 sign_bit = _mm256_set1_ps(-0.0f); __m256 inp_abs = _mm256_andnot_ps(sign_bit, inp); What's the logic behind it?. SSE/AVX: Choose from two __m256 float vectors based on…
user49626
  • 67
  • 4
1
vote
1 answer

Why doesn't std::abs() works with floats

The result of std::abs(0.5f) is 0 because there is no overload for floats. Why? I'm using G++.
1
vote
1 answer

How to get an absolute value from NSDecimalNumber?

How to get an absolute value from NSDecimalNumber? Getting absolute value from Integer is easy, but I need one from NSDecimalNumber. I have found answers from few years ago (Objective-C, for example), but I was hoping that in Swift in 2020 it is…
mallow
  • 2,368
  • 2
  • 22
  • 63
1
vote
1 answer

Odd behavior when decrementing a CCSprite velocity

My CCSprite subclass has two float properties called, velX and velY to keep track of the velocity of my player. When it gets swiped in the game layer, I figure out the vector direction of the swipe and start the player moving that way. In the…
Steve
  • 6,332
  • 11
  • 41
  • 53
1
vote
3 answers

How to get the absolute value while noting if the number used to be negative?

I have a genetic dataset where each row describes a gene and has a beta column with multiple beta values I've compressed into one row/cell (from the variant level where multiple variants in one gene gave multiple betas). The beta is the effect size…
DN1
  • 234
  • 1
  • 13
  • 38
1
vote
1 answer

Finding absolute difference between rows and comparing the difference with other rows

I have this dataframe. df = pd.DataFrame({'userId': [10,20,10,20,10,20,60,90,60,90,60,90,30,40,30,40,30,40,50,60,50,60,50,60], 'movieId':…
Sanwal
  • 307
  • 2
  • 11
1
vote
1 answer

Largest sum from absolute differences of N elements in an array

This isn't really a homework, but rather a practice and optimization, but this seemed like the best section for this type of questions. It is a dynamical programming issue, and it's the following: -Given an unsorted array of N elements, pick K…
Filip5991
  • 383
  • 1
  • 3
  • 13
1
vote
0 answers

Turn all values into absolute values in VBA

I need to convert all values that have negative values into absolute values. I'm working with the Kennedy Space Center to build a climatology based on 18 years worth of field mill data. Field mills measure electricity in the atmosphere values can…