arithmetic-expressions Questions

3

Solved

I wish to evaluate a vector of strings containing arithmetic expressions -- "1+2", "5*6", etc. I know that I can parse a single string into an expression and then evaluate it as in eval(parse(tex...
Bissonnette asked 26/7, 2014 at 20:25

25

Solved

I am trying to divide two image widths in a Bash script, but bash gives me 0 as the result: RESULT=$(($IMG_WIDTH/$IMG2_WIDTH)) I did study the Bash guide and I know I should use bc, in all examp...
Puppetry asked 4/10, 2012 at 7:16

3

Solved

From Hacker's Delight: 2nd Edition: The formula here seems a little bit awkward here. How is some x vector is subtracted from 1 vector (presumbly 0x1111 1111) when x is smaller than 1? (Like: (as...
Backpedal asked 30/10, 2020 at 8:38

4

The "arithmetic shift right" operation is similar to a normal (logical) shift right, except the most significant (i.e. shifted-in) bits are filled with the sign bit rather than 0. Unfortu...
Inly asked 17/6, 2023 at 6:49

1

Solved

Why does the following code: from decimal import Decimal result = Decimal('0') * Decimal('0.8881783462119193534061639577') print(result) return 0E-28 ? I've traced it to the following code in the ...
Siliculose asked 19/11, 2022 at 13:53

6

Solved

I'm trying a line like this: for i in {1..600}; do wget http://example.com/search/link $i % 5; done; What I'm trying to get as output is: wget http://example.com/search/link0 wget http://exampl...
Shivery asked 16/4, 2011 at 18:21

9

Solved

For example, does an operator exist to handle this? float Result, Number1, Number2; Number1 = 2; Number2 = 2; Result = Number1 (operator) Number2; In the past the ^ operator has served as an e...
Fabron asked 14/6, 2010 at 1:31

7

Solved

There are some special operators in Prolog, one of them is is, however, recently I came across the =:= operator and have no idea how it works. Can someone explain what this operator does, and also ...
Loera asked 13/9, 2009 at 8:59

1

Solved

I have a simple arithmetic expression data structure that I want to be able to print. For sake of simplicity here I have made an example with 3 binary operations, addition, multiplication and divis...
Piwowar asked 11/4, 2020 at 15:39

4

I'm trying to understand the instruction sets of old microcontrollers, especially the 6502. The documentation of the instruction set that can be found here lists two shift instructions (beside the...

4

Solved

I am working on a very simple bash script and I'm having a problem with understating why deprecated $[] is working flawlessly, while $(()) seems to break the whole thing. The code I'm referring to...
Dennet asked 14/10, 2016 at 1:19

3

I would like to convert a number that is stored in scientific notation into a floating point decimal, so I can then perform some comparisons on the data. This is being done in a bash script - here ...
Sherlynsherm asked 11/12, 2012 at 18:27

2

In the code I use an expression tree "3 + 2.53 - 1.75" that should return a result of 3.78. However, it ends up adding all the values within the string and outputs 7.28. I ran through the code mult...

9

In some code I see this: private void compute(Long a, Long b, Long c) { long result = a-(b+c); ... It seems a bit strange that the result is stored in a primitive long instead of a Long object ...
Moreland asked 31/5, 2013 at 10:30

4

Solved

I am being paranoid that one of these functions may give an incorrect result like this: std::floor(2000.0 / 1000.0) --> std::floor(1.999999999999) --> 1 or std::ceil(18 / 3) --> std::ceil...
Diageotropism asked 25/1, 2016 at 16:4

3

Solved

My application evaluates some integer expressions specified by the user. I want to detect all potential errors and report them. All computations are done in int64_t (signed). Formulas may include ...
Picture asked 13/6, 2018 at 12:15

2

Solved

I came accross this expression, and can't understand the meaning of line 3 in the following snippet: int A=0, B=0; std::cout << A << B << "\n"; // Prints 0, 0 A += B++ == 0; // h...
Endor asked 4/5, 2018 at 12:41

2

Solved

Say we have a BASH array with integers: declare -a arr=( 1 2 3 ) and I want to do an arithmetic operation on each element, e.g. add 1. Is there an altenative to a for loop: for (( i=0 ; i<=$...
Baboon asked 30/7, 2015 at 7:50

14

So I was trying to write the nth number in the Fibonacci sequence in as compact a function as possible: public uint fibn ( uint N ) { return (N == 0 || N == 1) ? 1 : fibn(N-1) + fibn(N-2); } B...
Mood asked 1/4, 2016 at 15:0

2

Solved

I am having troubles with the arithmetic expressions in a bash file (a unix file .sh). I have the variable "total", which consists of a few numbers separated by spaces, and I want to calculate the...
Empurple asked 18/7, 2017 at 17:43

1

Solved

I'm working through the second edition of the Rust handbook, and decided to try and make the classic Celsius-to-Fahrenheit converter: fn c_to_f(c: f32) -> f32 { return ( c * ( 9/5 ) ) + 32; } ...
Drawl asked 14/6, 2017 at 18:34

3

Solved

I am confused with how Scala handles division by zero. Here is a REPL code snippet. scala> 1/0 java.lang.ArithmeticException: / by zero ... 33 elided scala> 1.toDouble/0.toDouble res1: Do...
Evaluate asked 12/5, 2017 at 13:0

1

Solved

It is possible to record the time that was used to run some code using system.time. Here is a little example: system.time( mean(rnorm(10^6)) ) But I am not only interested in the time but also...
Gladden asked 2/5, 2017 at 15:13

6

Solved

I apologize if this is a simple question but I'm having trouble grasping the concept of modulus division when the first number is smaller than the second number. For example when 1 % 4 my book says...
Hansiain asked 1/5, 2013 at 1:52

1

Solved

With the following code: $a=1; $b=1; echo $a."%".$b." maradéka: "." = ".$a % $b."<br>"; echo $a."+".$b." összege: "." = ".$a + $b."<br>"; I get this output: 1%1 maradéka: = 0 ...
Sensualist asked 22/11, 2016 at 23:35

© 2022 - 2024 — McMap. All rights reserved.