8,369 questions
0
votes
0
answers
69
views
How to merge 2 double arrays in c [closed]
I need to write a function that merges 2 double arrays together into a single array. How would I go about doing that?
EDIT:
I have 2 arrays that like this for example: double arr1[] = {3.75, 4, 2.6} ...
2
votes
2
answers
151
views
C++ double type: is comparison by == valid if comparing against the previously set value
What I mean is: I have a situation that I have two fields in the structure of type double, where both may be set there through some evaluation, but in some situations the second of them can be equal ...
1
vote
1
answer
54
views
What is the difference between using (double) versus multiplying by 1.0 when type casting an integer to a double?
I was wondering what the difference is between converting an integer to a double using double versus multiplying the integer by 1.0
int a = 4
int b = 3
double c = 1.0 * a / b
double d = (double) a / ...
4
votes
1
answer
79
views
Given a double value x, why (signed long long)(x) != *(signed long long *)(&x)?
I wonder why the code below prints "wrong".
double x = 0x8000000000000000;
signed long long v1 = (signed long long)(x);
signed long long v2 = *(signed long long *)(&x);
printf( v1 == v2? ...
1
vote
0
answers
40
views
How to properly convert between types in Cython?
I have a function which looks like
cdef double __test_func(double x, double y, double z):
return (x-y)/((2*x-y)*y)**(0.5*z)
def test_func(x, y, z):
return __test_func(<double>x, <...
3
votes
2
answers
123
views
Convert Currency amount to cents without going through floating point
Consider this function:
function DollarsToCents(dollars: Currency): Integer;
begin
result := Trunc(dollars * 100);
end;
The expression dollars * 100 will get converted to an Extended, I believe, ...
2
votes
1
answer
91
views
opencv/modules/core/src/matrix_wrap.cpp:72: error: (-215:Assertion failed) 0 <= i && i < (int)vv.size() in function 'getMat_'
Can you help me with this bug?
a and b are 2-double array and are defined with rows and cols. a is a given matrix:
cv::resize(a,b,cv::Size(newrows,newcols),0,0,INTER_CUBIC);
I can compile, but got ...
0
votes
1
answer
108
views
Reading doubles (numbers) in and out of Excel cells
I'm reading in values from an Excel sheet and have the user checking those numbers/text and hitting save again if they are correct. It works well for any text and numbers, except for my discount being ...
2
votes
1
answer
179
views
How can I handle floating-point precision in C when dealing with numbers very close to zero or other edge cases
I wrote a program in C that calculates three points based on three points that are given. So we are given points A, B, C and calculate points A', B', C'. Now there are three ways that these points ...
0
votes
0
answers
22
views
Double values for triangle angles returning as NaN if 2+ side lengths are the same
I'm trying to write a program that will calculate the angles of a triangle using the side lengths (via the Law of Cosines, Law of Sines, and Triangle Sum Theorem). It works just fine if all the side ...
0
votes
1
answer
173
views
Double multiplied with int has become less accurate in .NET Core
I was experimenting with this code block with different versions of .NET:
using System;
using System.Linq;
public class Program
{
public static void Main()
{
...
10
votes
2
answers
871
views
In what range does incrementing and decrementing Java doubles work?
I'm writing a Java class that tracks a fractional number, but needs to be able to increment and decrement it. Using a double for this number seems to work fine for small values, but I'm trying to ...
1
vote
1
answer
78
views
Precision issues when converting double to float
JDK has a random method in ThreadLocalRandom:
nextDouble(startInclusive, endExclusive)
But no float version. Here I want to float version, this is my implementation:
public static float nextFloat(...
-1
votes
2
answers
125
views
If Statement Cannot Evaluate Basic Floating-Point Problem
I was working through Bjarne Stroustrup's "Programming-Principles And Practice Using C++" book and I'm currently stumped by the 5th "Drill" question of Chapter 4.
There is a series ...
1
vote
0
answers
63
views
Datatype double declaration
I had a problem where, my answers were completely similar to the ones on the online judge, but they were deemed wrong.
I fixed it after a lot of tinkering, but I dont understand what is going on. ...