math

Math Equation Web Control?

Is there any easy web application or user control that allows math equations to be easily created and stored as a text string? Update: An ASP.NET control would be ideal. ...

How to fix precision of variable

In c# double tmp = 3.0 * 0.05; tmp = 0.15000000000000002 This has to do with money. The value is really $0.15, but the system wants to round it up to $0.16. 0.151 should probably be rounded up to 0.16, but not 0.15000000000000002 What are some ways I can get the correct numbers (ie 0.15, or 0.16 if the decimal is high enough). ...

How to resolve a Java Rounding Double issue

Seems like the subtraction is triggering some kind of issue and the resulting value is wrong. double tempCommission = targetPremium.doubleValue()*rate.doubleValue()/100d; 78.75 = 787.5 * 10.0/100d double netToCompany = targetPremium.doubleValue() - tempCommission; 708.75 = 787.5 - 78.75 double dCommission = request.getPremium().do...

In Python, what is the difference between '/' and '//' when used for division?

Is there a benefit to using one over the other? They both seem to return the same results. >>> 6/3 2 >>> 6//3 2 ...

Finding the LCM of a range of numbers

I read an interesting DailyWTF post today, "Out of All The Possible Answers..." and it interested me enough to dig up the original forum post where it was submitted. This got me thinking how I would solve this interesting problem - the original question is posed on Project Euler as: 2520 is the smallest number that can be divided by...

Mathematics and Game Programming

I want to program graphical 2D games more complex than the basic 2D stuff I already know. I don't want to do 3D programming. Just more complex 2D stuff. I dropped high school before I could learn a lot of stuff so I walked away with enough algebra knowledge to balance my checkbook and do some light 2D Cartesian programming. Are there an...

Statistical tools for programmers

I'm trying to evaluate the purchase of a statistical tool. This will be used in part by non-programming users (doing clinical studies) and in part by programmers, so I'm trying to find a good compromise between usability and automation. Of course, cost is an issue, but if I can build a solid case, we could probably buy a commercial packa...

Multiplication of very long integers.

Is there an algorithm for accurately multiplying two arbitrarily long integers together? The language I am working with is limited to 64-bit unsigned integer length (maximum integer size of 18446744073709551615). Realistically, I would like to be able to do this by breaking up each number, processing them somehow using the unsigned 64-bi...

A Project Euler Puzzler (specifically in PHP)

There is another recent Project Euler question but I think this is a bit more specific (I'm only really interested in PHP based solutions) so I'm asking anyway. Question #5 tasks you with: "What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?" Now, I have solved it twice. Once very inefficiently and ...

Unique random numbers in O(1)?

The problem is this: I'd like to generate unique random numbers between 0 and 1000 that never repeat (I.E. 6 doesn't come out twice), but that doesn't resort to something like an O(N) search of previous values to do it. Is this possible? ...

How to calculate center of an ellipse by two points and radius sizes

While working on SVG implementation for Internet Explorer to be based on its own VML format I came to a problem of translation of an SVG elliptical arc to an VML elliptical arc. In VML an arc is given by: two angles for two points on ellipse and lengths of radiuses, In SVG an arc is given by: two pairs of coordinates for two points on e...

C# - Is there a 32-bit float math libary?

I'm planning on doing my next project in c# rather than c++ (using SlimDX). All of directX uses floats, however System.Math uses doubles. This means constantly converting between floats and doubles. So idealy id like to write all the code using floats, since i'm not getting any added precision converting to floats from doubles all the ...

Books & resources to teach myself Linear Algebra

The title says it all basically, I'm looking for books and resource to teach myself linear algebra to be used in 3D graphics programming. I prefer practical approaches to teaching over theoretical (even though math is what, 99.99% theory?) ones, so the dream resource for me would be a book that tackles linear algebra as it's used with 3D...

Non-deterministic finite state machines in software development?

Recently I've been thinking about finite state machines and how I would implement them in software (programming language doesn't matter). My understanding is that deterministic state machines are in widespread use (parses/lexers, compilers and so on). Okay, that's great. But what's the matter with non-deterministic state machines? I kn...

Recommendations for a small c-based vector and matrix library.

I'm in need of a lightweight library for 2d & 3d vectors and 3x3 & 4x4 matrices. In basic C. Just so I don't reinvent the wheel suboptimally. Any suggestions? ...

Tools for sparse least squares regression

Hi, I want to do sparse high dimensional (a few thousand features) least squares regression with a few hundred thousands of examples. I'm happy to use non fancy optimisation - stochastic gradient descent is fine. Does anyone know of any software already implemented for doing this, so I don't have to write to my own? Kind regards. ...

How to fade out volume naturally?

I have experimented with a sigmoid and logarithmic fade out for volume over a period of about half a second to cushion pause and stop and prevent popping noises in my music applications. However neither of these sound "natural". And by this I mean, they sound botched. Like an amateur engineer was in charge of the sound decks. I know th...

Perl golf: Print the powers of a number

What's the shortest Perl one-liner that print out the first 9 powers of a hard-coded 2 digit decimal (say, for example, .37), each on its own line? The output would look something like: 1 0.37 0.1369 [etc.] Official Perl golf rules: Smallest number of (key)strokes wins Your stroke count includes the command line ...

Python Inverse of a Matrix

How do I get the inverse of a matrix in python? I've implemented it myself, but it's pure python, and I suspect there are faster modules out there to do it. ...

Scheduling a worker with overlapping periodic tasks

With one worker, who can only perform one task at a time (but can switch between tasks instantly) Given a list of tasks, -- defined as "n seconds, every m seconds" (eg, 5 seconds every 3600 seconds) How could I find the best starting times and count for each task? If every task were "1 second, every 60 seconds", each would have an uni...