Tagged Questions
1
vote
1answer
76 views
Signed & unsigned integer multiplication
In fixed point math I use a lot of 16bit signals and perform multiplication with 32bit intermediate results. For example:
int16_t a,b,c;
c = (int16_t)(((int32_t)a * (int32_t)b)>>14);
Lets ...
1
vote
2answers
40 views
c language symmetry in different cmath log() and exp() implementations?
Follow-up from the question Are cmath exp() and log() functions always symmetrical?
double x;
double y = exp(log(x));
assert(x == y);
Essentially, if one writes log(x) to disk and calculated exp() ...
-2
votes
0answers
67 views
Square Root in C [closed]
I was asked by a friend to build a simple program that could find an answer to a quadratic formula. I have finished almost everything but I need help finding a square root in C. I know that when you ...
0
votes
3answers
79 views
Are cmath exp() and log() functions always symmetrical?
Are cmath exp() and log() functions always symmetrical?
Ergo if I do
double x;
double y = exp(log(x));
assert(x == y);
will the assert ever fail, and in that case: under what circumstances? We can ...
1
vote
1answer
58 views
Galois LFSR explanation of code
I am trying to understand how the galois LFSR code works. On the wikipedia page there is a figure with an example. There is a C snippet code.
#include <stdint.h>
uint16_t lfsr = 0xACE1u;
...
-1
votes
2answers
35 views
Objective-c: map a range
I have a variable with values ranging from 0 to 4000, but need to convert the value so it outputs 0 to 1 instead.
In arduino, there's a function called, map:
map(value, fromLow, fromHigh, toLow, ...
-2
votes
1answer
71 views
How to find the largest squares that can be used to tile a rectangular sheet of paper? [closed]
Given the length and breadth of a sheet of paper, we have to divide the sheet into squares of equal sizes. We want to find the number of squares the paper would be cut into if we cut it into squares ...
-1
votes
2answers
42 views
math.h default rounding mode not clear
I am facing very strange fact about rounding of float and conversion to int.
As is stated here:
http://www.gnu.org/software/libc/manual/html_node/Rounding.html
Rounding to nearest representable ...
1
vote
1answer
63 views
Numerical integration of a complex function with Cubature C package
I want to use the Cubature C package to perform a multidimensional integral of a complex function. I tried to do it in the following way for the very simple function f(x,y) = x + y*i over the square ...
0
votes
2answers
61 views
fmod function from math.h library in C not working correctly?
Ok, so hopefully I do not look like an idiot from asking this question...as it is quite basic, but my brain is either on vacation or something is indeed wrong.
So -4 % 5 or -4 mod 5 should equal 1 ...
1
vote
3answers
129 views
Optimized way to handle extremely large number without using external library
Optimized way to handle the value of n^n (1 ≤ n ≤ 10^9)
I used long long int but it's not good enough as the value might be (1000^1000)
Searched and found the GMP library http://gmplib.org/ and ...
1
vote
2answers
48 views
how to convert longitude and altitude to a grid with equal(nearly) area on the Earth sphere in Matlab or C/C++?
The range of longitude and latitude of Earth sphere are [-180, 180] and [-90, 90] respectively. I want to get equal area grids by 0.5 deg * 0.5 deg (area around the equator).
As the distortion ...
1
vote
6answers
84 views
Numerical differential equation solver algorithm segfaults unexpectedly
I was trying to solve a differential equation in octave but it takes forever with the differential unit I have chosen, so I decided to code it in C. Here is the algorithm:
#include <stdio.h>
...
1
vote
3answers
89 views
Convert negative angle to positive: Involves invalid operand use
I am attempting to convert a negative angle (in degrees) to positive. But I am getting a compile error saying:
test.cpp invalid operands of types 'double' and 'int' to binary 'operator%'
...
1
vote
1answer
60 views
Using math.h sqrt function in C [duplicate]
Reading the documentation for math.h, it seems like all I should have to do is include math.h, and use the math functions included, such as sqrt. The problem is I get the following error when trying ...