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

Does x * x (and similar) lead to constraint violation if x has enumerated type?

C11, 6.2.5 Types, 18: Integer and floating types are collectively called arithmetic types. C11, 6.2.5 Types, 16: An enumeration comprises a set of named integer constant values. Each distinct enumeration constitutes a different enumerated…
pmor
  • 5,392
  • 4
  • 17
  • 36
1
vote
2 answers

What is the best way to realize high precision arithmetic calculations in JavaScript?

I'm doing an algorithm that checks if a number is prime for college, but I came across a connotation and calculation problem where I need to consider large numbers. One of them was solved with the support of BigInt(), however in arithmetic…
user17386646
1
vote
2 answers

How do you format a query to do arithmetic between the results of two MySQL select statements?

We know how to do simple MySQL arithmetic - e.g.: mysql> select 10-7 as 'result'; +--------+ | result | +--------+ | 3 | +--------+ But if "10" and "7" are themselves results of MySQL select queries, how do we do the math? - e.g.: select…
1
vote
1 answer

Calc a value on its decimal version

1 gwei = 0.000000001 ether There's a program that displays only 156489673002 (156 gwei), which is 0.000000156489673002 ether. But how to, in Bash, calculate how many ether is 156489673002 (so the output is 0.000000156489673002)?
1
vote
3 answers

What is the casting order of operations in arithmetics in c++?

Why does result = static_cast(1 / (i+1)) return int in C++ and why does result = 1 / (i+static_cast(1)) return double? Specifically why is casting after the +-operation sufficient to produce a double. Why is it not required…
infinite789
  • 325
  • 1
  • 8
1
vote
1 answer

Expression Evaluation Oz/Mozart

I am trying to create a function that takes an expression and evaluates it. Expressions can contain the following operations: Integers - described by a tuple int(N), where N is an integer. Addition - described by a tuple add(X Y), where both X and…
Nhabbott
  • 166
  • 1
  • 3
  • 13
1
vote
2 answers

How to include binary arithmetic operators in native pipe

I am trying to integrate binary arithmetic operators in the native pipe. Reproducible example: # without pipe round(sample(1:2, 1) / 3, 2) ## [1] 0.33 # with pipe 1:2 |> sample(1) / 3 |> round(2) ## [1] 0.3333333 # round is ignored 1:2 |>…
vonjd
  • 4,202
  • 3
  • 44
  • 68
1
vote
1 answer

Calculate arithmetic calculation on floating numbers in shell scripting

I have created 5 arrays which contains only floating numbers (contains positive and negative numbers). Following are the arrays which are declared: assets reported debit credit affiliate loans I need to perform below formula on the arrays but it's…
blackhole
  • 214
  • 1
  • 11
1
vote
1 answer

Is there a way to store an arithmetic operator in a variable and use the variable itself within a calculation in JavaScript?

Using the following 3 variables - I wanted to calculate two numbers with whatever the operator variable was set to. For example -> num1 * num2.. const num1 = 10; const num2 = 4; const operator = `*`; //Could be any arithmetic operator I know this…
1
vote
0 answers

floating point arithmetics: interpolating two half-precision floating point values with one full-precision interpolation

let's say I have two IEEE 32bit floating point values a and b plus one IEEE 32bit fp interpolation value x (something between 0 and 1) so I get the interpolated result: float a = 123.456f; float b = 654.321f; float result = a * (1.0f-x) + b *…
matthias_buehlmann
  • 4,641
  • 6
  • 34
  • 76
1
vote
2 answers

How to divide the number of words from the number of characters of a file in bash script using arithmetic expansion and wc

Here is my work: wc -w $3/lab1.txt words=$(wc -w $3/lab1.txt) wc -m $3/lab1.txt characters=$(wc -m $3/lab1.txt) echo $((characters / words)) The two variables that I have setup work perfectly and they give the correct output but when I try to…
bryan123
  • 17
  • 1
  • 7
1
vote
1 answer

Voyager golden record binary arithmetic

I just read the article about the Voyager gold record cover,however, I do not understand the binary arithmetic of the left-hand corner, As you can see from the image below,, can some one please explain this binary arithmetic for me comprehensively?…
Cn Hu
  • 57
  • 6
1
vote
1 answer

Why do divisions not work in jsonpath-ng?

Jsonpath-ng offers basic arithmetic as in: from jsonpath_ng import jsonpath from jsonpath_ng.ext import parse jsonpath_expr = parse('$.foo * 2') target = {'foo': 2} result = jsonpath_expr.find(target) result = [match.value for match in…
EzPizza
  • 979
  • 1
  • 13
  • 22
1
vote
2 answers

Arithmetic in Prolog - Multiples of a number

I want to create a function multiples(X, N, R) where R is a list containing all multiples of X from X to X * N. An example would be: multiples(3, 4, [12, 9, 6, 3]), which should give out true. My code so far: multiples(X, N, R) :- X >= 1, N >= 1, Z…
1
vote
3 answers

How to check if a column data is an arithematic progression in PostgreSQL

Suppose i have a column C in a table T, which is as follow: sr c 1 34444444444440 2 34444444444442 3 34444444444444 4 34444444444446 5 34444444444448 6 34444444444450 How can i verify or check if the values in Column C are…