Skip to main content

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.

Filter by
Sorted by
Tagged with
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, ...
ayr's user avatar
  • 130
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 ...
lucmobz's user avatar
  • 71
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: ...
Hosein Javanmardi's user avatar
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^...
vibe's user avatar
  • 1,078
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, ...
Hosein Javanmardi's user avatar
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^...
Tim's user avatar
  • 1,281
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,...
Tim's user avatar
  • 1,281
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 ...
Tim's user avatar
  • 1,281
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 ...
Xyrph's user avatar
  • 9
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 ...
Jack Sike's user avatar
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 ...
Rahul Shah's user avatar
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 ...
Bananach's user avatar
  • 809
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 ...
D.Hutchinson's user avatar
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, ...
Exp HP's user avatar
  • 121
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, ...
Dror Speiser's user avatar
-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 ...
user20973's user avatar
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 ...
boxofchalk1's user avatar
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 ...
Raibyo's user avatar
  • 219
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 ...
Peter Cordes's user avatar
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 ...
Simon Goodman's user avatar
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 ...
benblumsmith's user avatar
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 ...
bzm3r's user avatar
  • 659
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 ...
bzm3r's user avatar
  • 659
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 ...
kesari's user avatar
  • 287
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 ...
kesari's user avatar
  • 287
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, ...
carsten's user avatar
  • 133
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&...
a06e's user avatar
  • 1,739
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?
Victor's user avatar
  • 103
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 ...
user avatar
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. ...
Karthik's user avatar
  • 143
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 ...
Sneftel's user avatar
  • 173
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 ...
Geoffrey Irving's user avatar
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 ...
Thomas W.'s user avatar
  • 800
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 ...
Thomas W.'s user avatar
  • 800
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 ...
Andrew's user avatar
  • 711
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?...
Tim's user avatar
  • 1,281
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 ...
Phonon's user avatar
  • 673