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

difference between $[a-b] and $((a-b)) in bash

I don’t know this operator $[] and couldn’t find something about it. However I know that next two codes give the same output a=4 b=1 echo $[a-b] # => 3 and a=4 b=1 echo $((a-b)) # => 3 So what is $[] operator for, and what’s the difference with…
Ulysse BN
  • 10,116
  • 7
  • 54
  • 82
2
votes
1 answer

Specializing variadic template with using

Good evening, I am having trouble with specialzing a variadic template. I need the following template: template using OPT = decltype(operator+(std::declval()...))(Ts...); The problem is, this doesn't compile, when I try to…
user3617992
  • 359
  • 1
  • 8
2
votes
5 answers

Why does '+' operator behave abnormally in JavaScript?

I'm learning JavaScript. I tried putting double quotes around different digits in an JavaScript expression and I got surprised with the third result from below code statements. Consider below code statements and their output present in a comment…
2
votes
1 answer

Does Sightly really not support any arithmetic operators?

I'm trying to subtract 2 from the total number of items in a list in Sightly.
  • ${itemList.size -2 @ context='number'}
The result…
Snapznaz
  • 23
  • 1
  • 3
2
votes
2 answers

simple arithmetic operation in huge amount of number c#

I want to perform simple arithmetic operation in huge amount of number, as implement below string t = "22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"; …
Faraz Ahmed
  • 1,467
  • 2
  • 18
  • 33
2
votes
1 answer

Find number coprime to modulus

I've been doing some research on the RSA encryption system, it's pretty simple to code one using small primes, as there aren't too many possibilities and performance is not a real issue. Here's how RSA Works: First, you generate a n value, product…
Juanco
  • 33
  • 1
  • 6
2
votes
1 answer

SilverStripe arithmetic in template

I want to do a simple arithmetic operation in a .ss template. <% loop $Images %> <% $Pos == 4 %> and {$TotalItems - 4} more foto's $Break <% end_if %> <% end_loop %> For example I would want to…
Matiss
  • 5,079
  • 2
  • 27
  • 27
2
votes
4 answers

What can bool type return in C99?

What is bool guaranteed to return as? Can I rely on a bool type to always be interpreted as 0 or 1? If bool's numerical interpretation isn't reliable in C99 is there a standard where it is? Are there any things I should look out for in LLVM, GCC, or…
2
votes
4 answers

Rounding to nearest power of two in bash

I'm shell scripting and I want to round a given integer to the nearest power of two. We can use any standard tools available from the linux command line. You can assume bash. So arithmetic expansion as well as bc would be available. Rounding to the…
Wes Modes
  • 2,024
  • 2
  • 22
  • 40
2
votes
2 answers

How to Properly Use Arithmetic Operators Inside Comprehensions?

I am dealing with a simple csv file that contains three columns and three rows containing numeric data. The csv data file looks like the following: Col1,Col2,Col3 1,2,3 2,2,3 3,2,3 4,2,3 I have hard time figuring out how to let my python…
MEhsan
  • 2,184
  • 9
  • 27
  • 41
2
votes
1 answer

How do i perform arithmetic operations with function pointers?

So..I understand that if i take(*ptr) as some function f then res = (*ptr)(a,b) is the same as res = f(a,b). So now my problem is that I have to read in 3 integers. First 2 are the operands, third is the operator e.g. 1 = add, 2 = subtract, 3 =…
CHEWWWWWWWWWW
  • 169
  • 3
  • 20
2
votes
5 answers

Python: How to check the data type of key-value pair of an object?

I am creating a function to add the marks of each array(homework, quiz, test) inside an object(student1). There definitely arises errors as the code tries to add "Lloyd". I want to check the data-type of value of "name" so as to carry the arithmetic…
madhur
  • 101
  • 2
  • 7
2
votes
2 answers

Arithmetic operation on all elements in BASH array

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<=${#arr[@]}-1 ; i++ )) ; do arr[$i]=$(( ${arr[$i]} + 1…
FelixJN
  • 540
  • 3
  • 16
2
votes
4 answers

LISP arithmetics implementation

I'm making a toy lisp interpreter with D and I don't know the theory of Lisp very well. I was wondering if Lisp can implement basic arithmetic functions (+, -, ×, ÷) by itself. Most Lisp/Scheme dialects implemented it with the builtins of C,…
user4283874
2
votes
2 answers

Why does Bash with -e option exit when 'let' expression evaluates to 0?

I am struggling to understand why the bash -e option exits this script. It happens only when the expression calculated gives 0: #!/bin/bash set -ex table_year=( 1979 1982 1980 1993 1995 ) year=$1 let…
PBrockmann
  • 303
  • 5
  • 16