Questions tagged [arithmetic-expressions]

An arithmetic expression is an expression that results in a numeric value. There are two kinds of numeric values, integers (whole numbers), and real or floating point numbers (numbers containing a decimal point).

677 questions
2
votes
1 answer

Combine expressions and parameter expansion in bash

Is it possible to combine parameter expansion with arithmetic expressions in bash? For example, could I do a one-liner to evaluate lineNum or numChar here? echo "Some lines here Here is another Oh look! Yet another" > $1 lineNum=$( grep -n -m1 'Oh…
2
votes
2 answers

Why do these parentheses give different answers in C?

I was working on readability for CS50 PS 2, and was getting incorrect outputs on the grade level. Debugging showed that the input values were correct, but the output was wrong. Hand calculating using the inputs gave the correct answer. I…
2
votes
1 answer

How to divide Pandas DataFrame with multiple square root values?

Here is an example of my DataFrame: X Y 4.2 3.0 6.8 4.7 8.4 2.1 I would like implement a formula but ran into some errors. I would like find the value for X squared divided by the summation of X squared + Y squared. The formula would look…
Able Archer
  • 579
  • 5
  • 19
2
votes
1 answer

Finding a relationship without knowing the operators?

1 + 2 + 3 = 6 is a simple equation, but let's say you have something like this: 1 ? 2 ? 3 = 6 How do you find the operators? Is it possible? I've experimented a bit with gplearn in Python but it seems like you need to know at least some of the…
2
votes
1 answer

Rust ndarray arithmetic operation unexpected type mismatch

I'm having a problem when trying to perform an arithmetic operation on two Array1s of the ndarray crate. I have tried to reduce my problem to a the following reprex: #[macro_use(array)] extern crate ndarray; use ndarray::Array1; fn main() { let…
Luke Skywalker
  • 1,464
  • 3
  • 17
  • 35
2
votes
1 answer

How to do BigInt arithmetic in Dart 2.x, specifically division?

Dart documentation says that BigInt division returns a value of type 'double'. This is a problem. To illustrate, here are two implementations of an algorithm involving division. The first is in Kotlin, the second is in Dart. The Dart version runs…
Fred
  • 564
  • 10
  • 21
2
votes
2 answers

Google sheets query functions: how to do arithmetic on columns with non-constants, i.e. dividing not by a constant but by another cell?

I understand how to do arithmetic on a column using a query function as long as I'm using a fixed constant. However, if I try to do the same using a cell reference instead of a constant, I get an error. I've tried making the cell a named range and…
2
votes
1 answer

Arithmetic expression evaluation oz mozart

I have a problem and I don't really know how to implement it in OZ: Suppose that you are given an arithmetic expression described by a tree constructed from tuples as follows: An integer is described by a tuple int(N), where N is an integer. An…
Alma A
  • 138
  • 10
2
votes
3 answers

Why is 02000 evaluated to 1024

Out of curiosity, I wrote a program like this: auto number1 = 100; auto number2 = 02000; auto number3 = 2; auto result = (number1 + number2) / number3; std::cout << result; Interestingly, the program outputs 562. So, in visual studio, i hovered…
Hemil
  • 916
  • 9
  • 27
2
votes
0 answers

R: times operation (^)

I would like to speed up "times" operation(^) in R. x <- rnorm(2e+5) require(rbenchmark) benchmark(x^(3.33), x^2, x^1, replications = 500) test replications elapsed relative user.self sys.self user.child sys.child 1 x^(3.33) 500 …
minem
  • 3,640
  • 2
  • 15
  • 29
2
votes
1 answer

Split an arithmetic expression with a regex

I want to split an expression like -1*-0.8/5-5 into [ '-1', '*', '-0.8', '/', '5', '-', '5' ] [ '-1', '*', '-0.8', '/', '5-5' ] This is what I'm getting right now with expression.split(/([*/])/g); Any suggestions on this?
jc127
  • 343
  • 2
  • 13
2
votes
4 answers

Absolute value squared of a complex number in Fortran

Is there an intrinsic function in Fortran to compute the square modulus |z|^2 of a complex number z? If not, is there a simpler or better way to compute it than the following? REAL(z, precision_specifier)**2 + AIMAG(z)**2
norio
  • 3,652
  • 3
  • 25
  • 33
2
votes
0 answers

Arithmetic expression compiler to VHDL with ANTLR4 (need better approach)

I'm working on application which will generate VHDL code for given arithmetic expression. I decided to use ANTLR4 and JavaFX for this purpose. So far i created grammar. It is writen for + - * / operations and integer, float numbers. But it is not…
2
votes
1 answer

PetitParser arithmatic script from textbook is not working. It keeps saying ParseOn is nill?

I am learning how to use PetitParser on Pharo, Smalltalk and I am using a textbook to learn it. In the textbook, the following script is given. term := PPDelegateParser new. prod := PPDelegateParser new. prim := PPDelegateParser new. term…
2
votes
2 answers

Prolog:: f(x) recursion

I'm a beginner to Prolog and have two requirements: f(1) = 1 f(x) = 5x + x^2 + f(x - 1) rules: f(1,1). f(X,Y) :- Y is 5 * X + X * X + f(X-1,Y). query: f(4,X). Output: ERROR: is/2: Arguments are not sufficiently instantiated How can I add value of…
mdo123
  • 1,757
  • 3
  • 16
  • 34