Given two integers a and b, is there an efficient way to test whether there is another integer n such that a ≤ n2 < b?
I do not need to know n, only whether at least one such n exists or not, so I hope to avoid computing square roots of any numbers in the interval.
Although testing whether an individual integer is a perfect square is f...
Hello. I need to calculate the standard deviation of a generic list. I will try to include my code. Its a generic list with data in it. The data is mostly floats and ints. Here is my code that is relative to it without getting into to much detail:
namespace ValveTesterInterface
{
public class ValveDataResults
{
private ...
I have a single triangle and a plane (in 3 dimensional space), How would I calculate the line segment where the two cross, if there is no crossing then I need to detect this case.
The end result I'm looking for is two 3 dimensional vectors, which define the start and end points of the line segment.
To help you out a little, I have alre...
I have to take a piece of data, and apply a large number of possible variables to it. I really don't like the idea of using a gigantic set of if statements, so i'm looking for help in an approach to simplify, and make it easier to maintain.
As an example:
if (isSoccer)
val = soccerBaseVal;
else if (isFootball)
val = footballBa...
Lets say I have a value of 3.4679 and want 3.46, how can I truncate to two decimal places that without rounding up?
I have tried the following but all three give me 3.47:
void Main()
{
Console.Write(Math.Round(3.4679, 2,MidpointRounding.ToEven));
Console.Write(Math.Round(3.4679, 2,MidpointRounding.AwayFromZero));
Console.Wr...
I have a latitude/longitude value and distance value. I need to calculate a bounding box with the given location as the center. so if the distance was 200 meters then the rectangle box should be 200 meters in front, behind, to left and right.
How do I go about doing this using JavaScript?
...
int num = 5;
int denom = 7;
double d = num / denom;
this results in 0, I know you can force it to work by doing
double d = ((double) num) / denom;
but there has to be another way, right? I don't like casting primitives, who knows what may happen.
...
In a company, there are three categories: A,B,C.
They want to give an increment. So if category C gets N% as increment. category B gets 2N% as increment and category A gets 3N% as increment. But the increment should be atleast 1% and The total updated salary should not exceed $50,000.
Print the increment and the total update...
If I have two vector coordinates representing positions on the surface of the earth where the center of the earth is (0,0,0) and the Up vector is (0,0,1);
What is the best way to calculate a 3d plane that is running along the two vectors (the direction v2 - v1) but back by a set number of meters (just imagine a virtual clip plane that i...
I need to switch from the XY co-ordinate system shown above to the X'Y' co-ordinate system using System::Drawing::Drawing2D (i.e. GDI+). This is what I have in mind:
float rotation = // +90 below is because AB is the new vertical...
Math::Atan2(pB.Y - pA.Y, pB.X - pA.X) * 180.0 / Math::PI + 90.0f;
Matrix m;
m.T...
i want to compare do simple math in django template
like {% forloop.counter > 5 %}
{% endfor %}
how do i achieve this?
...
I'm a c# noob but I really need a professional's help. I am using visual studio 2005 for a project so I don't have math.linq I need to calculate the standard deviation of a generic list of objects. The list contains just a list of float numbers, nothing too complicated. However I have never done this before so i need someone to show me t...
Hey guys, I'm trying to compute the cumulative distribution function of the standard normal distribution for a formula in C using the GSL (Gnu Statistics Library)
I've installed and included gsl but am having trouble understanding how to use it.
I think the function I need is:
double gsl_ran_lognormal (const gsl_rng * r, double zeta, ...
i want to compare do simple math in django template
like {% forloop.counter > 5 %} {% endfor %}
how do i achieve this?
...
Given a point P on a 'canonical' ellipse defined by axes a, b, and an arc length s, how can I find a point Q, also on the ellipse, that is s clockwise along the elliptical curve from P — such that if I were to start at P and 'walk along' the elliptical curve for a distance of s, I would reach Q — programatically and without breaking the ...
Consider the problem of counting the number of structurally distinct binary search trees:
Given N, find the number of structurally distinct binary search trees containing the values 1 .. N
It's pretty easy to give an algorithm that solves this: fix every possible number in the root, then recursively solve the problem for the left a...
I'm building a heatmap-like rectangular array interface and I want the 'hot' location to be at the top left of the array, and the 'cold' location to be at the bottom right. Therefore, I need an array to be filled diagonally like this:
0 1 2 3
|----|----|----|----|
0 | 0 | 2 | 5 | 8 |
|----|----|----|----|
1 | 1 | 4...
I want to know how to get an angle of a line A-B from horizontal axis X. Other questions in SO do that only between two lines. I'm aware I can always draw second line A-C and calculate but I'm wondering if there's a faster method.
EDIT: I'm very sure I'm not doing a premature optimization.
...
what is the most efficient way to calculate the least common multiple of two integers
I just came up with this, it definitely leaves something to be desired
int n = 7, m = 4, n1=n, m1=m;
while (m1 != n1) {
if (m1 > n1)n1 += n;
else m1 += m;
}
System.out.println("lcm is " + m1);
...
How to get the rectangular co ordinates between two points in javascript as an object? for example foo(10, 20, 30, 40) shold return (10, 40) and (30, 20)
...