math

how to get a float from int

i has a int: int f=1234;//or f=23 f=456 ... i want to get: float result=0.1234; // or 0.23 0.456 ... dont useing: float result = parseFloat ("0."+f); what's best way to do? thanks ...

Does this method work for solving the quadratic equation using JavaScript?

I'm trying to do some "complex" math where I need to call upon some of JavaScript's Math properties to solve the quadratic equation. Does the following method work? root = Math.pow(inputb,2) - 4 * inputa * inputc; root1 = (-inputb + Math.sqrt(root))/2*inputa; root2 = (-inputb - Math.sqrt(root))/2*inputa; Does this look co...

Easiest way to determine time complexity from run times

Lets suppose I am trying to analyze an algorithm and all I can do is run it with different inputs. I can construct a set of points (x,y) as (sample size, run time). I would like to dynamically categorize the algorithm into a complexity class (linear, quadratic, exponential, logarithmic, etc..) Ideally I could give an equation that more...

Turn a negative number into a positive for probability

I want to create an array that sends a pixel in a specific direction. It has four options: Forward, Backward, Left, Right Each direction has an associated score that is its probability of sending the pixel in a specific direction. Example: Direction[Forward] = 20; Direction[Backward] = 12; Direction[Left] = -5; Direction[Right] = 2; ...

calcute angle between two Latitude/Longitude points

Is there a way to calculate angle between two Latitude/Longitude points? What I am trying to achieve is to know where the user is heading. For example, user is heading North, South,.... South-East, etc. But I have only two points (Lng/Ltd) Thx ...

divide 64bit in two 32bit registers by 32bit

I am trying to write an x86 emulator in JavaScript for education purposes. I have already written a compiler and at the moment I am trying to write the x86 emulator in JavaScript. I have however a problem with the DIV instruction. According to http://siyobik.info/index.php?module=x86&id=72 DIV takes a 64bit number as input by interp...

Finding eigenvectors of covariance matrix to create 3D bounding sphere

I'm currently in the process of writing a function to find an "exact" bounding-sphere for a set of points in 3D space. I think I have a decent understanding of the process so far, but I've gotten stuck. Here's what I'm working with: A) Points in 3D space B) 3x3 covariance matrix stored in a 4x4 matrix class (referenced by cells m0,m1,m2...

Algorithm to determine most popular article last week, month and year?

I'm working on a project where I need to sort a list of user-submitted articles by their popularity (last week, last month and last year). I've been mulling on this for a while, but I'm not a great statitician so I figured I could maybe get some input here. Here are the variables available: Time [date] the article was originally publ...

Smallest integer larger than lg N

I was reading somewhere that: The smallest integer larger than lg N is the number of bits required to represent N in binary, in the same way that the smallest integer larger than log10 N is the number of digits required to represent N in decimal. The Java statement for (lgN = 0; N > 0; lgN++, N /= 2) ; is a si...

Function one-to-one and onto from set to an other

Hello, I saw somewhere that if we have a one-to-one function from sets X to Y mean that we have a onto function from Y to X. I can't understand it !! Someone can explain ?? ...

Javascript math parser library

Is there a good math parser in Javascript? I want to be able to parse something like: LOG(3.14)+5^2+POW(2,LN(X*2,Y)) Thanks, ...

How to construct a repeating equation?

Suppose two integers x and N. I'm trying to determine how to construct an algorithm that would return an integer of the value x repeated N times. So if x was 9 and N was 4, the equation would return 9999. And if x was 9 and N was 5, the equation would return 99999. (ad nauseam) I hope this isn't completely absurd or out of place on SO...

Algorithm for schematizing (metro) maps

This is a long shot, but I thought I might try before starting the dirty work. I've got a project to build an application which will, for a defined input stations (vertices) and lines (edges), that is, a real map of some public transportation, schematize a given map into a metro map. I've done some research on the problem and it's an NP...

Sieve of Eratosthenes - Finding Primes Python

Just to clarify, this is not a homework problem :) I wanted to find primes for a math application I am building & came across Sieve of Eratosthenes approach. I have written an implementation of it in Python. But it's terribly slow. For say, if I want to find all primes less than 2 million. It takes > 20 mins. (I stopped it at this poi...

Optimum algorithm to calculate pythagorean triplet

I have a question for everyone. I have this problem statement where in given, x^2 + y^2 = c is the equation, you have to optimally find the tuples (x,y) such that the equation holds true. Given a variable c, whose value is known, you have to find the values (x,y). So suppose if you have c=0, then x=0 and y=0. Suppose you have c=2, then...

Good algorithms book with proofs of the algorithms?

Possible Duplicate: What book to use to learn Algorithms and Data Structures ? I need a good book on algorithms with mathematical proofs of the complexity and the algorithm itself. Can you recommend me one? ...

How to convert a number 30.006649999999994 to 30.01 in js?

Anyone knows such a function in javascript? ...

Math Question in JS - How do I get a ratio from a percentage

I'm trying to make a converter, but i don't know the formula to do this, for example, how do I get the ratio of 85694 of 30711152. So, i can get the % like 85694/30711152*100=0.28 (rounded) but how do I then get the ratio of like 1 in a 100? I believe that'd be around 1:400? But i don't know how to get it exactly or what formula to use.....

selecting a random element of the power set.

For a problem that I'm working on right now, I would like a reasonably uniform random choice from the powerset of a given set. Unfortunately this runs right into statistics which is something that I've not studied at all (something that I need to correct now that I'm getting into real programming) so I wanted to run my solution past some...

Calculating the spread of the hash function for a hashmap which uses chaining

Hello everyone, I am writing a generic hash map in C++ which uses chaining to deal with collisions. Say if I have a hash map with 11 buckets, and I insert 8 items. The hash function will distribute it as follows: bucket[0] = empty bucket[1] = 2 elements bucket[2] = empty bucket[3] = 1 element bucket[4] = 1 element bucket[5] = 3 eleme...