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
2
votes
3 answers

What method in Java returns the absolute difference of two integers?

Is there a method in the Java Math class that returns the absolute difference of two integers? int absDiff = 8 - 15; int answer = 7;
Plus Ultra
  • 59
  • 1
  • 9
2
votes
3 answers

Bash script to add absolute values of numbers seperated by spaces

I need a bash script to find the sum of the absolute value of integers separated by spaces. For instance, if the input is: 1 2 -3 the script should print 6 to standard output I have: while read x ; do echo $(( ${x// /+} )) ; done which gives…
Steve Zee
  • 71
  • 5
2
votes
2 answers

Return Absolute Value of a Google Sheet cell with AppScript

In Google Sheets, I'm trying to return the absolute values of a cell, using app script. So far I have the following code: var SEARCH_COL_IDX = 1; // variable that indicates which column to search, 0 = column A function SearchInventario() { var ss …
Riggs
  • 23
  • 6
2
votes
1 answer

Changing the method of calculating the line of best fit

In using R's lm() function to calculate the line of best fit for my data, I've run into an issue: one or two major outliers in my data set are forcing the line to be somewhere where it doesn't help me understand my data. My goal is to change the…
2
votes
3 answers

How do I incorporate absolute value within my Pandas dataframe?

id Impressions_Source Impressions_Source2 15020 150201 151920 I am trying to figure out how to calculate a percentage difference (discrepancy) between two values utilizing absolute value. Here is my formula used df['Discrepancy_Num'] =…
Bo. Allen
  • 31
  • 3
2
votes
1 answer

Python abs() function failing on negative number

I'm working in python3.6 on linux and came across a pretty obvious failure of the abs() function. My variable x ended up as a very large negative number (possibly -inf), but the absolute value abs() function still returned a negative number, which…
jk_sri
  • 91
  • 5
2
votes
1 answer

why does filter + abs functions not give correct value

numbers = list(range(-10,10)) print(numbers) newnum = filter(abs,numbers) print(list(newnum)) print(abs(-10)) it gives the output as below [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [-10, -9, -8, -7, -6, -5, -4, -3, -2,…
Gupta
  • 314
  • 4
  • 17
2
votes
2 answers

Absolute value without branching or shifts, only add/sub and booleans

We got this problem at school for students that want to test themselves. I have spent quite some time on this but can't figure it out. You have 16-bit number in AX register, this number is signed. Get its absolute value, the number in AX has to…
Adam
  • 21
  • 4
2
votes
1 answer

Absolute value in objective function of linear optimization

I'm trying to find the solution for the following expression Objective function: minimize(| x - c0 | + | y - c1 |) Constraint: 0 < x < A 0 < y < B where c0, c1, A, B are positive constants Following the conversion given in …
2
votes
1 answer

How to find the absolute value of an integer in Two's complement in ARM

If I have -2 (11111111111111111111111111111110), is there a neat ARM instruction or a series of such that will make it (00000000000000000000000000000010). OR or XOR would not work from what I have tried since I loose the 30th bit. Thank you
boinka
  • 145
  • 1
  • 11
2
votes
4 answers

Why is the absolute value of a complex number a floating point number?

In python3: >>> abs(-5) == 5 and >>> abs(5) == 5 but >> abs(5+0j) == 5.0
skypen
  • 199
  • 2
  • 10
2
votes
1 answer

How to Select ABS(Value) when a condition is being met in SQL Server 2014?

When an Account is 'PrePaid' (PlanCode = P0100) then the balance owing is in negative (eg; -100 if they are owing $100. When an Account is 'PostPaid' (PlanCode = P0200) then the balance owing is positive (eg; 100 if they are owing $100) Some…
user1777929
  • 777
  • 1
  • 10
  • 28
2
votes
1 answer

plotting in R with absolute values

I wonder if there is a straightforward way to plot the following two equations in R x and y are variables and the rest are known parameters. when X is a vector of dimension n then
Nile
  • 303
  • 2
  • 11
2
votes
2 answers

Absolute value function in Rust

In this elementary Rust program a function calculates the absolute value of an integer, and main() helps in completing a statement with the result: fn main() { let value = abs(-4); println!("{}.", value); } fn abs(x: i32) -> i32 { …
A. N. Other
  • 409
  • 4
  • 14
2
votes
3 answers

Use cases of 'signum' for ordered numeric types in Haskell

The signum function is the implementation of the usual mathematical definition of sign, which conditionally returns a value in {-1,0,1}. It is a theoretical definition, and as such, it doesn't take into account computational costs of operations, or…
enrique
  • 492
  • 3
  • 11