in reply to optimization problem

My current program demonstrates this very well.

Could you show us that program, or at least a short version of it? (SSCCE) Also, this sounds like a case where you might benefit from a test-first approach: even if you don't have the body of your function yet, you can still write tests using Test::More to test this hypothetical function. Not only will it help you see how close you're getting while you're developing, it'll help us understand your problem description better :-)

use warnings; use strict; use Test::More; sub my_func { my $target = shift; my @weights = @_; my @output = (); # TODO! return \@output; } is_deeply my_func(30, 7,10,13), [10,10,10]; is_deeply my_func( 5, 3,7,11), [3,3]; # TODO: lots more test cases! done_testing;
If it were all in whole numbers it would be trivial.

In my experience integers are much easier to work with, and you don't suffer from floating-point imprecisions. I'd suggest switching to milligrams, micrograms, etc. - for example, my Perl (64 bit) can handle integers up to 9007199254740992 without loss of precision. (source)