Questions tagged [computer-arithmetic]

For questions concerning finite precision arithmetic in computers and other related concepts.

116 questions
12
votes
3 answers

Why do so many computer programming language implementations have trouble with the remainders of negative integers?

As most of us know, or should know, $-7 \equiv 1 \pmod 4$. But if you use Java's modulus operator %, you get -3 for the answer, not 1. That's technically correct, but it can cause problems if you're not aware of this as you write a program. C# and…
8
votes
1 answer

Prerequisite reading for Concrete Mathematics?

I'm a freshman computer science major who has just started reading Concrete Mathematics, mathematics for computer science. Is there any prerequisite reading or learning I should do before embarking on reading this book?
5
votes
1 answer

Is there still a fast invsqrt magic number for float128?

template T union_cast(U data){ union{U a;T b;}t{data}; return t.b; } float128_t quick_invsqrt_with_magic_num(int128_t mnum,float128_t X){ auto x= union_cast(mnum - (union_cast(X) >> 1)); return…
5
votes
1 answer

Mathematics of two's complement

I am trying to understand the underlying mathematics of two's complement. Googling the topic gives me a lot of articles on how to invert the digits and add one, and why computers use this system rather than more straight forward binary addition.…
Avatrin
  • 1,615
4
votes
3 answers

Differences between signed and unsigned decimal values

What are examples of signed and unsigned decimal values? What are the differences between them?
Bilis
  • 125
3
votes
2 answers

Why does Eulers Theorem not work in this case?

In my number theory textbook I am tasked with finding the value of $5^{30}\mod 62$. As the last section had been about Eulers Theorem which states that for any $a,n\in\mathbb{Z}$ where the $\gcd(a,n)=1$ $$a^{\phi(n)}\equiv1\mod n$$ The first thing I…
Ilikemath
  • 358
3
votes
1 answer

UPD: Structure of subgroups of $S_{2^n}$ generated by $\langle x \mapsto ax \mod 2^n \rangle$ and linear groups

It's a very well known result by Gauss that $(\mathbb{Z}/2^n \mathbb{Z})^\times = \langle -1 \rangle \times \langle 3 \rangle \cong C_2 \times C_{2^{n-2}}$. Consider a faithful action $\mathrm{mul}: (\mathbb{Z}/2^n \mathbb{Z})^\times \to…
3
votes
1 answer

How to represent subset using 5-bit binary code?

For the set $V=\{a, e, i, o, u\}$, give the $5$-bit binary string that codes each of the following subsets: $\{a, i,o\}; \{e\}; V; \emptyset$; Which subset is represented by the $5$-bit string $10001$? Can I know how do you get the 5-bit binary…
3
votes
0 answers

Error bound for floating-point interval dot product

In Handbook of Floating-Point Arithmetic (Birkhäuser, 2010, Chapter 6) Muller et al. presented the following absolute forward error bound for the floating-point recursive dot product: $$ \left|RecursiveDot (a, b) - \sum_{i=1}^n a_ib_i\right| \le…
3
votes
3 answers

Floating point approximation to logarithms by powers and bit counting?

Earlier I both asked questions and found some interesting sources on the internet of how to do approximate division by combining and counting number of $0$s following most significant bit in denominator. Example: We represent a fraction $7/3$ as two…
3
votes
1 answer

SICP: Why does this recursion-based sine approximation work?

Here is the question and solution to Structure and Interpretation of Computer Programs' exercise 1.15 (see here). My problem is, I don't know how the combination of these formulae actually work: $$sin(x) = 3sin(x/3) - 4sin^3(x/3)$$ and $$sin(x) =…
3
votes
2 answers

Converting $\frac{2}{7}$ to a binary number in a $32$ bit computer

I want to convert $\frac{2}{7}$ to a binary number in a $32$ bit computer. That is, $1$ bit is assigned to the sign of the number, $8$ bits are assigned to the exponent, and $23$ bits are assigned to the mantissa. So $x = \pm q \times 2^{m}$ where…
3
votes
1 answer

Determine sign of sum of square roots

Problem Given positive square-free integers $r_i$ and non-zero integers $a_i$, is there an algorithm for determining the sign of $\sum_{i=1}^n a_i\sqrt{r_i}$ without calculating approximations for the square roots? If $n=2$ it is easy and I hope it…
user70612
2
votes
1 answer

IEEE754 32-bit single precision format

I have a question like this: Show how the number $-12.75$D is stored in the computer's storage using IEEE754 32-bit single precision format. You are required to show your conversion steps clearly. My answer…
Bilis
  • 125
2
votes
0 answers

On the complexity of big integer multiplication

There seems to be something I am deeply missing about the assumptions while calculating the complexity of multiplication Let us say we have two number m,n, that we want to multiply and we have n>m, and Log(n) = bwe have a set of primes $p_1, p_2,…
1
2 3 4 5 6 7 8