Questions tagged [computer-arithmetic]
For questions about the particulars of doing math on computers, e.g. floating point numbers, over/underflow, implementing arithmetic operators/functions for binary numbers.
37 questions
0
votes
0
answers
44
views
Advanced computing on FPGA
I am an absolute beginner in the FPGA topic (so far I have only implemented a couple of simple logic gates in Verilog and simulated them in ModelSim). I studied digital electronics, logic elements, ...
7
votes
1
answer
203
views
Unexpected result when summing sorted (and unsorted) positive floating point numbers
I am exploring Higham's excellent Accuracy and Stability of Numerical Algorithms and chapter 4 is dedicated to summation.
So I decided to test the most basic thing. Summing positive random numbers ...
3
votes
1
answer
81
views
Dynamic tolerance in a conditional loop to obtain maximum precision allowed by machine floating point numbers
I have coded a simple program for a root finding problem using Halley's method. Here is the code:
...
6
votes
3
answers
214
views
Method to compute $a^n - b^n$
Given two floating point numbers $a,b$ with $a > b$ and an integer $n$, what is the most accurate way to compute
$$
a^n - b^n
$$
? We can assume both $a,b$ are between 1 and 2. Lets assume both $a^...
4
votes
1
answer
127
views
Summation of trigonometric functions results in error with finite precision
Consider the following expression:
$$f(t) = B+\sum_{k=1}^{N} A_k\cos(\omega_kt)$$
where $A$ and $B$ are known. the frequencies are also known but are not multiples of a fundamental frequency. However, ...
1
vote
1
answer
100
views
What does this definition of two's complement representation of signed integers mean?
I am reading a book on digital circuits. It says that
given a n-bit binary number $N$, its two's complement representation is itself, if $N$ is positive; and its two's complement representation is $2^...
2
votes
2
answers
2k
views
Is `#define INT_MIN 0x80000000` okay?
In Computer Systems: a Programmer's Perspective:
Writing TMin in C
In Figure 2.19 and in Problem 2.21, we carefully wrote the value of TMin32 as -2,147,483,647-1. Why
not simply write it as either -2,...
2
votes
2
answers
196
views
How can I detect lost of precision due to rounding in both floating point addition and multiplication?
From Computer Systems: a Programmer's Perspective:
With single-precision floating point
the expression (3.14+1e10)-1e10 evaluates to 0.0: the value 3.14 is lost ...
0
votes
0
answers
134
views
Division and Modulus for Large DIVISORS
Excel and also Excel VBA have no built-in support for arbitrary precision arithmetic. There are a few very large add-ins that can be installed to do these sorts of calculations where the operands are ...
0
votes
1
answer
54
views
Problems with first and second complement
What I know 1=negative,0=positive
Example 1. 27-13=14
Example 2. -39+92=53
For example 1. 27 to binary is 11011
13 to binary is 1101
So 1101 change to two complement will ...
4
votes
3
answers
1k
views
Best software to do big number calculations quickly
I am trying to do some work on some math conjecture. I am testing the conjecture numbers using very large math numbers (100+ digits ). I am currently using python to test these numbers.
In the ...
2
votes
2
answers
187
views
Evaluating $\log(\exp(x)+1)$ for negative $x$
With double precision, I get $\log(\exp(-3)+1)=0.048587351573741958$, which already has $4$ incorrect digits, and $\log(\exp(-30)+1)=9.348... \times10^{-14}$, which only has two correct digits.
What ...
3
votes
1
answer
1k
views
Is the exponential function, e^x, very expensive to compute in Matlab and harmful to my computer?
Is the exponential function exp() problematic and very expensive to compute in Matlab?
When I write a new term for my model of ODEs that has an exponential term in ...
2
votes
1
answer
116
views
Performing computations over the set of constructable numbers
The set of constructable numbers is commonly defined in one of two ways:
the set of finite numbers reachable from the rational numbers through a finite sequence of addition/subtraction, ...
3
votes
1
answer
2k
views
Fast(er) computation of dot product of two convolutions?
Let $a,b,c,d\in\mathbb{R}^n$. Is it possible to compute
$$\langle a*b,c*d\rangle$$
faster than 6 FFTs?
I can do it with 6 FFTs by doing normal convolutions, 3 FFTs each.
In my application I know $b, ...
-2
votes
2
answers
154
views
Array initialization in C
In this bit of code, the X and Y arrays should be identical but for some reason, that I CANNOT figure out for the life of me, X[0] is always 1 rather than 0. I have tried initializing the whole array ...
9
votes
4
answers
470
views
Small, unpredictable results in runs of a deterministic model
I have a sizable model (~5000 lines) written in C. It is a serial program, with no random number generation anywhere. It makes use of the FFTW library for functions using FFT - I do not know the ...
1
vote
2
answers
66
views
MATLABs double arithmetic
this is a classical problem, but I need help to pinpoint what I am missing.
Problem:
In MATLAB
(exp(1) + 10^12) - 10^12
gives you a double which equal to e, up to 5 correct digits. But I thought ...
10
votes
0
answers
894
views
Implementing std::nextafter: Should denormals-are-zero mode affect it? If so, how?
This might be the wrong stackexchange site for this question. math.SE, cs.SE, programmers.SE, and of course stackoverflow are all possibilities. I'm hoping to reach an audience that might actually ...
2
votes
0
answers
1k
views
Divide and Conquer division algorithm explained (as used in GMP bignum)
I am trying to understand the divide and conquer division algorithm that is used in the GMP bignum arithmetic library.
The code is very optimised and that makes it somewhat hard to understand. the ...
2
votes
0
answers
392
views
How to construct a subring of a polynomial ring in Magma
This is a question about the computer algebra system Magma. I have been looking for a place to ask this type of question on the SE network and scicomp.SE was suggested to me; hopefully it finds a home ...
3
votes
1
answer
967
views
How can I avoid roundoff error when calculating the difference $\textrm{erfc}(a) - \textrm{erfc}(b)$?
In this excellent answer, it is recommended that one make use of the $\textrm{erfcx}$ function to avoid roundoff error in calculating dealing with $x < 25$ (approximately). So, one scales their ...
5
votes
1
answer
70
views
How would I figure out when a function would be at the "brink of underflow"?
User hardmath, provided an excellent overview of how to handle overflow when calculating the product of two functions, where one is likely to overflow: https://scicomp.stackexchange.com/a/20913/9466
...
3
votes
2
answers
4k
views
what does -ffast-math do?
What kind of optimisations does the option -ffast-math do ?
I saw that the time taken for a simple $O(n^2)$ algorithm being reduced to that of an $O(n)$ algorithm ...
3
votes
2
answers
1k
views
performance of icc main.cpp == g++ -ffast-math main.cpp
I have a program that has a nested loop, together with its parent running at $O(n^2)$ complexity performing floating point arithmetic.
I see that the performance of the code when compiled with ...
3
votes
3
answers
893
views
Exact analytical matrix inversion of sparse 100x100 matrices in C++
I need to invert a matrix. Of course, I'm not the first person in this situation, and I know that there's a wealth of powerful libraries out there, of which I only know a couple.
That being said, ...
4
votes
1
answer
217
views
Compute hypergeometric function ratio: $\frac{_{2}F_{1}(a+1,b;c;x)}{_{2}F_{1}(a,b;c;x)}$?
I need a numerically stable way to compute the following ratio:
$$\frac{_{2}F_{1}(a+1,b;c;x)}{_{2}F_{1}(a,b;c;x)}$$
All the parameters are real numbers, with $a< 0$,$\ $ $b,c > 0$ and $0<x&...
0
votes
1
answer
79
views
How many years it would take our laptops to be as fast as the fastest super computer in 2000 [closed]
How many years it would take our laptops to be as fast as the fastest super computer in 2000 according to Moore's law?
3
votes
1
answer
162
views
Fibonacci, variation on the theme
I am trying to calculate the numbers $n$ for which the $n$-th Fibonacci number $F_n$ is a multiple of $n$; that is fib(n)%n==0.
Here is the best PARI code I could come up with (for the counting ...
4
votes
1
answer
4k
views
range of positive mantissa in given floating-point number representation
I am a student and I came to this question while solving problems regarding the float-points.
...
6
votes
2
answers
146
views
How many bits to unambiguously represent fixed-point division?
Suppose I have a function which divides an $m$-bit unsigned integer $a$ by an $n$-bit unsigned integer $b$ and returns the quotient as a fixed-point number with $t$ fractional bits, truncating towards ...
2
votes
2
answers
127
views
Integer arithmetic support on future HPC systems
I writing some robust geometric algorithms using quantization + integer arithmetic for evaluating exact predicates. However, since BlueGene's integer support is so terrible, it occurred to me that ...
8
votes
3
answers
2k
views
Need for quad precision in scientific computing?
Even if quad precision is not directly supported by most CPUs, many Compilers (GNU, Intel) support them. Also some software packages allow to compile with quad precision, e.g. PETSc. But is there ...
6
votes
2
answers
334
views
Krylov subspace iterative methods in floating point arithmetic
Is there any work that considers Krylov subspace iterative methods in floating point arithmetic? I'm especially interested in how rounding errors influence the convergence and the accuracy of the ...
14
votes
4
answers
656
views
In floating point arithmetic, why does numerical imprecision result from adding a small term to a difference of large terms?
I have been reading the book Computer Simulation of Liquids by Allen and Tildesley. Starting on page 71, the authors discuss the various algorithms that are used to integrate Newton's equations of ...
11
votes
3
answers
1k
views
Which is computed faster, $a^b$, $\log_a c$ or $\sqrt[b]{c}$?
Which is computed faster, $a^b$ or $\log_a c$ or $\sqrt[b]{c}$? $a$, $b$ and $c$ are positive reals with $b>1$.
What kinds of algorithms will you use in the comparison? What are their complexities?...
57
votes
3
answers
27k
views
Why is division so much more complex than other arithmetic operations?
I recently encountered a case where I needed an integer division operation on a chip that lacked one (ARM Cortex-A8). While trying to research why that must be, I found out that in general division ...