Questions tagged [saturation-arithmetic]

Saturation arithmetic limits results of all operations to a fixed range between a minimum and maximum value; the results are "saturated" at the limits.

  • If a result is greater than the maximum, it is set ("clamped") to the maximum
  • If it is below the minimum, it is clamped to the minimum.

Properties like associativity and distributivity may fail in saturation arithmetic.

Examples (i.e. limits are -100..100)

  • 60 - 50 = 10 (no saturation)
  • 60 + 50 = 100 (saturated)
  • (60 + 50) - 50 = 50 (saturated)
  • 60 + (50 - 50) = 60 (no saturation)
  • 10 × 11 - 11 = 89 (saturated)
26 questions
2
votes
2 answers

C - Saturating Signed Integer Multiplication with Bitwise Operators

Alright, so the assignment I have to do is to multiply a signed integer by 2 and return the value. If the value overflows then saturate it by returning Tmin or Tmax instead. The challenge is using only these logical operators (! ~ & ^ | + << >>)…
Smreks
  • 317
  • 1
  • 7
  • 19
2
votes
1 answer

Importance of Q(Saturation Flag) in ARM

I want to understand the importance of Q flag in ARM Processor. I know there are certain instructions like QADD,QSUB etc. But I need to understand this with some examples which will clarify the concept.
1
vote
0 answers

ColorMatrix Saturation and OpenCV Saturation result are different

Below is the C# Logic for changing saturation of image. Referred from here Note: We are using this saturation matrix R G B A W R [sr+s sr sr 0 0] G [ sg sg+s sg 0 0] B [ sb sb sb+s 0 0] A [ 0 0 0 1 0] W [ 0 …
Banng
  • 531
  • 1
  • 6
  • 19
1
vote
0 answers

Using CSS filter to increase Saturation on webpage and Streaming video container

I'm using a super simple CSS filter to increase Saturation on a webpage (and it's video's) via Stylus extension, html { filter: Saturation (125%) } it works on the webpage without issue but then the embedded video's are blacked out with sound…
Mekboy
  • 11
  • 1
1
vote
1 answer

Mult plus shift left ops using MMX assembler instructions

I am looking for doing shl(mult(var1,var2),1) operation, where mult multiplies var1 and var2 (both are 16-bit signed integers) and shl shifts left arithmetically the multiplication result. Result must be saturated, i.e., int32 max or int32 min if…
LooPer
  • 1,459
  • 2
  • 15
  • 24
1
vote
2 answers

Fast saturating integer conversion?

I'm wondering if there is any fast bit twiddling trick to do a saturating conversion from a 64-bit unsigned value to a 32-bit unsigned value (it would be nice if it is generalized to other widths but that's the main width I care about). Most of the…
1
vote
2 answers

How to handle addition and subtraction beyond Integers MAX_VALUE and MIN_VALUE?

The following is the piece of code I am trying to implement: if (n1 > 0 && n2 > 0 && result >= Integer.MAX_VALUE) { result = Integer.MAX_VALUE; } else if (n1 > 0 && n2 > 0 && (result <= Integer.MIN_VALUE || result < 0)) { result =…
0
votes
4 answers

Add two vectors (uint64_t type) with saturation for each int8_t element

I was recently faced with a given problem: There are 8 elements in the vector, each is represented by int8_t. Implement an algorithm in x86_64 that will add two vectors (uint64_t type). Adding elements should be done with saturation arithmetic…
0
votes
2 answers

Do you know any saturation function? To make number fit to given range?

Looking for a saturating function in Rust. Here I called it fit_to_range(range). let input:i64= something; let saturated:64= input.fit_to_range(7..=4000); assert!((7..=4000).contains(saturated));
Sir
  • 337
  • 1
  • 7
0
votes
1 answer

GCC complier :strange behavior when doing float operation , float value saturating to 65536 where float is of 4 bytes

[I tried to compute a float multiplication, I observed the value was getting saturated to 65536 and was not updating. the issue is only with the below code.]1 Result for the above code I tried this with online GCC compiler the issue was still the…
0
votes
0 answers

How to solve a saturation problem with AWS EC2 t2.micro

Instance t2.micro Detail : ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20200716 Hello I run a python script on a EC2 instance. It is a very simple script which extract data from a webpage. My instance overloads very quickly. Here are some…
ahmedaao
  • 377
  • 1
  • 3
  • 14
1
2