Sorting negative and positive numbers in objective c 
sortedArray = [numberArray
sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
float first = [(NSNumber *)a[@"price"] floatValue];
float second = [(NSNumber *)b[@"price"] floatValue];
if (first > second) {
return NSOrderedDescending;
} else if (first < second) {
return NSOrderedAscending;
}
return NSOrderedSame;
}];

Rand() returns negative numbers when min and max are positive 
It's because range * rand() overflowed and wrapped around.
This approach can't be "fixed", because you would just get RAND_MAX of the
range possible values, leaving big holes that would never be chosen. (Or,
if (INT_MAX  INT_MIN + 1) / (RAND_MAX + 1) is smaller than RAND_MAX,
that's how many distinct results you can get)
Use the new C++11 random number generators.
If you can't use C++11, then use bitshifting and OR operators to combine
multiple rand() results into a single number. If you got a number outside
your range, just try again. Any method of mapping one range onto another
will break most of the nice properties of the pseudorandom number, like
uniform distribution.

Removing negative numbers from NSArray in Objective C 
the one you wrote is an array of strings, if that's ok you can loop the
array and remove strings that starts with  using
Since you cannot remove objects while iterating, you can create a new array
and store only positive numbers (or mark item to be deleted and delete
after the loop)
NSMutableArray onlyPositives = [[NSMutableArray alloc] init]
for(int i=0; i < [result count]; i++)
{
if(![result[i] hasPrefix:@""])
[onlyPositives add:[result[i]]
}

How do I make my positive integer become negative and stay negative until the end of my action? 
If the code works fine when slide = 1, I would suggest removing this:
if (slide >= 2) {
if (x < 0) {
x = x;
}
if (y < 0) {
y = y;
}
checkBoundariesTouching();
}
If you need that code to move the boxes back on the screen, you can put the
if statements inside a separate method and call that method when you change
slides.

How to set Positive / Negative Button in DialogFragment? 
Please take a look at the createDialog() method of DialogFragment.
Here is an example:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setTitle("Title")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int
whichButton) {
// DO SOMETHING
}
}
)
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int
whichButton) {
// DO SOMETHING
}
}
)
.create

How a positive value becomes negative after casting byte in Java? 
When you cast 128 (10000000 in binary) to an eightbit byte type, the sign
bit gets set to 1, so the number becomes interpreted as negative. Java uses
Two's Complement representation, so 10000000 is 128  the smallest
negative number representable with 8 bits.
Under this interpretation, 129 becomes 127, 130 becomes 126, and so on,
all the way to 255 (11111111 in binary), which becomes 1.

How to find a positive or negative value inside a string? 
Try adding an optional minus sign in the regular expression:
Dmin = re.search('(?<=DateMinEnd=)?w+', text)
 is the minus sign itself, and ? marks that there may be one or zero minus
symbols (in other words it's optional).

Extract positive and negative vales from Matrix 
You may use the find function and logical indexing
POS = [find(A(:,3)>0) A(A(:,3)>0,3)]
NEG = [find(A(:,3)<=0) A(A(:,3)<=0,3)]
For your input matrix being A
A = [1 5648.00278672228 46.43159546036
1 5650.38906894239 68.81787768047
1 5649.13081105839 4867.55961979647
1 5650.53055771227 4868.95936645035
1 5647.95215053492 4866.38095927300
1 5650.21656586142 2328.64537459950
1 5651.76371933598 7870.19252807406
1 5649.87288540620 1168.30169414428]
the results will be (with format shortG)
POS =
2 68.818
4 4869
5 4866.4
7 7870.2
NEG =
1 46.432
3 4867.6
6 2328.6
8 1168.3
the second find was

d3.js stacked bar chart with positive and negative values 
I was having the same problem. After all I came with the following
solution:
data.forEach(function (d) {
var newD = {x: d[xcoord]};
var y0neg = 0;
var y0pos = 0;
newD.values = color.domain().map(function (m) {
if (d[m] > 0)
return { name: m, y0: y0pos, y1: y0pos += +d[m] };
else {
var y1 = y0neg;
return { name: m, y0: y0neg += d[m], y1: y1 };
}
});
newD.totalPositive = d3.max(newD.values, function (v) { return v.y1});
newD.totalNegative = d3.min(newD.values, function (v) { return v.y0 });
arranged.push(newD);
});
This is the way to arrange your data. I suppose that the variable d holds
the values for each item for given x coordinate. The data collection is a
list of values such as:
{
'xcoord':'january

store positive number and negative in different vector 
Assuming v being your std::vector<int> vector and 0 being positive,
you just need to loop over the vector and store positive numbers in one
vector and negative numbers in the other:
using std::vector;
vector<int> pos, neg;
for (vector<int>::const_iterator it = v.cbegin(); it != v.cend();
it++) {
if ((*it) >= 0) pos.push_back((*it));
else neg.push_back((*it));
}
A std::vector<int>::const_iterator is used here because you do not
need to modify the original vector in any sense, you are just reading its
values.

C struct timeval timersub() negative value to positive 
Check which time value is bigger to determine which order to provide the
operands:
if (left_operand.tv_sec > right_operand.tv_sec)
timersub(&left_operand, &right_operand, &res);
else if (left_operand.tv_sec < right_operand.tv_sec)
timersub(&right_operand, &left_operand, &res);
else // left_operand.tv_sec == right_operand.tv_sec
{
if (left_operand.tv_usec >= right_operand.tv_usec)
timersub(&left_operand, &right_operand, &res);
else
timersub(&right_operand, &left_operand, &res);
}

Java regex with a positive look behind of a negative look ahead 
The comma appears because the capturing group contains it.
You can make the outside capture group noncapturing with (?:)
(?<=(?:,(?!.*Q(.*)E))).*

How do I do string indexing using negative to positive indexes? 
Not possible in a single range. But you can split it in two valid ranges.
string = "hello world"
string[4..1] + string[0..2] # => "orldhel"
You could write a function that accepts a single reversed range and does
this. I'll leave it to you as an exercise.
Update (don't use this in your actual code)
class String
alias_method :old_brackets, :[]
def [](idx)
if idx.is_a?(Range) && idx.begin < 0 && idx.end >
0
old_brackets(idx.begin..1) + old_brackets(0..idx.end)
else
old_brackets(idx)
end
end
end
string = "hello world"
string[4..2] # => "orldhel"

d3 negative and positive bar graph (histogram with a difference) 
You can make the checks when assigning the class that determines the
highlight
.attr("class", function(d, i) {
var clas = "";
negative: if(d.value < 0) {
for(var j = i+1; j < data.length; j++) {
if(data[j].value > 0) break negative;
}
clas = "bar negative";
}
positive: if(d.value > 0) {
for(var j = i+1; j < data.length; j++) {
if(data[j].value < 0) break positive;
}
clas = "bar positive";
}
return clas;
})
Updated jsfiddle here.

ggplot2 positive and negative values different color gradient 
You can always pad the results by a little bit when graphing in order to
avoid the white range entirely and exclusively show light yellow and light
cyan for numbers right around 0:
dat$Y2 < ifelse(dat$Y > 0, dat$Y + .25, ifelse(dat$Y < 0,
dat$Y.25,dat$Y))

Android getOrientation() returns azimuth, positive or negative? 
No, if the positive direction of Z points to the sky then when y axis
points to West then the angle is positive. But the coordinate used in
getOrientation the positive direction of Z points down to the earth, thus
now what seems counterclockwise becomes clockwise, so West is negative.

python positive and negative number list possiblities 
For just numbers, you can use itertools.product to create all combos, after
generating a list with both positive and negative numbers:
from itertools import product
def foo(nums):
return list(product(*((x, x) for x in nums)))
Demo:
>>> foo([4])
[(4,), (4,)]
>>> foo([1, 3])
[(1, 3), (1, 3), (1, 3), (1, 3)]
>>> foo([1, 3])
[(1, 3), (1, 3), (1, 3), (1, 3)]
>>> foo([1, 3, 4])
[(1, 3, 4), (1, 3, 4), (1, 3, 4), (1, 3, 4), (1, 3, 4), (1, 3, 4),
(1, 3, 4), (1, 3, 4)]

Why does this if condition fail for comparison of negative and positive integers 
The problem is in your comparison:
if ((1) < SIZE)
sizeof typically returns an unsigned long, so SIZE will be unsigned long,
whereas 1 is just an int. The rules for promotion in C and related
languages mean that 1 will be converted to size_t before the comparison,
so 1 will become a very large positive value (the maximum value of an
unsigned long).
One way to fix this is to change the comparison to:
if (1 < (long long)SIZE)
although it's actually a pointless comparison, since an unsigned value will
always be >= 0 by definition, and the compiler may well warn you about
this.
As subsequently noted by @Nobilis, you should always enable compiler
warnings and take notice of them: if you had compiled with e.g. gcc Wall
... the compiler would have warned you of your bu

Why Positive and Negative Look Ahead Regex is not supported in Oracle 
Use this regular expression to get the desired result
select regexp_substr('a,b','[^,]+', 1, level) from dual
connect by regexp_substr('a,b', '[^,]+', 1, level) is not null

Adding positive / negative Button to DialogFragment's Dialog 
You have to override the DialogFragments onCreateDialog(...) method:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setTitle("title")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int
whichButton) {
// do something...
}
}
)
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int
whichButton) {
dialog.dismiss();
}
}
)
.create();
}
Take

Matching negative and nonnegative numbers in perl 
Does this meet your needs?
/^w+s*?w+$/
It says match:
w+: any number of alphanumeric characters (including underscore)
s*: any number of spaces (if you need atleast one space, use s+)
?: optional dash
w+: any number of alphanumeric characters (including underscore). If this
set of characters can only be numbers, then use d+ instead.

JQuery variable: how to convert positive height into negative margin? 
You can convert string to int using parseInt(). Please check a code below :
var footerheight = $("#footer").height();
var marginTop = parseInt(footerheight) * 1;
$("#footer").css("marginTop", marginTop + "px");

Why does numeric_limits::min return a negative value for int but positive values for float/double? 
By definition, for floating types, min returns the smallest positive value
the type can encode, not the lowest.
If you want the lowest value, use numeric_limits::lowest instead.
Documentation: http://en.cppreference.com/w/cpp/types/numeric_limits/min
As for why it is this way, I can only speculate that the Standard committee
needed to have a way to represent all forms of extreme values for all
different native types. In the case of integral types, there's only two
types of extreme: max positive and max negative. For floats there is
another: smallest possible.
If you think the semantics are a bit muddled, I agree. The semantics of
the related #defines in the C standard are muddled in much the same way.

How to organize data that alternates between negative and positive values in Python 
def takeSection(sequence):
it = iter(sequence)
a = 1
group = []
while True:
try:
a, last = next(it), a
except StopIteration:
if group:
yield group
return
if a < 0 and last >= 0:
if group:
yield group
group = [a]
else:
group.append(a)
>>> sequence = [2323, 2324, 53434, 1027, 34232, 343434, 5657,
6565, 6500, 343434, 3434, 565, 5845, 4667, 5453, 98356]
>>> list(takeSection(sequence))
Out[2]:
[[2323, 2324, 53434, 1027, 34232, 343434, 5657, 6565, 6500],
[343434, 3434, 565, 5845, 4667, 5453, 98356]]
Edit
If you want to filter this on the first value in a pair of values, you can
change the if condi

Find all continuous subsets with a particular sum(+ve or ve) where the subset can contain both positive and negative integers 
No, there is no way, because there exist Nelement arrays having O(N^2)
slices with a given sum. Just enumerating the output takes O(N^2).
Example: the array { +1, 1, +1, 1 ... } (length N = 2k+1) with desired
sum +1.
there are N2 slices of length 3 summing up to +1
there are N4 slices of length 5 summing up to +1
... there are 3 slices of length N2 summing up to +1
there are 1 slices of length N summing up to +1
Total: 1 + 3 + ... + N2 = 2 * (1 + 2 + ... + k)  k = k^2

MySQL query to treat a column as positive or negative depending on another value 
how about this:
select sum(
case type
when 'deposit' then amount
when 'withdrawal' then amount
end
) as balance
from $table where userid = $id

Python... display positive even numbers up to... 
Two tips, since this is an assignment and you haven't posted any code.
The range function can produce the list you want. It takes 3 parameters,
the start of the list, the stop (which is not included in the list), and
the step. Since you're counting every other number, your step is 2.
The sum function would be quite useful.

How to print a formatted string with a space before positive numbers and + 
Use String.format("%s, next year you'll be +%d", "Michael", 37);
This will print, Michael, next year you'll be +37
Just a tip, most people tend to capitalize their class files, ie, First
instead of your name, first. Of course if you are working alone you can
name anything anyway you want and whatever you want to call it. But, if you
start working with teams then you should try and work on your format.
Edit: Someone commented that you want a space so just throw in a space like
this, + %d

Correct ratio of positive to negative training examples for training a random forestbased binary classifier 
This might seem like a trivial answer but the best thing I can suggest is
to try on a small subset of your data (small enough that the algorithm
trains quickly), and observe what you accuracy is when you use 11, 12,
13 etc...
Plot the results as you gradually increase the total amount of examples for
each ratio and see how the performance responds. Very often you'll find
that fractions of the data get very close to the performance of training on
the full dataset, in which case you can make an informed decision to your
question.
Hope that helps.

mysql query count consecutive positive numbers in a column 
select GREATEST(
sum(if (A <= 0, 0,1)),
sum(if (B <= 0, 0,1)),
sum(if (C <= 0, 0,1)),
sum(if (D <= 0, 0,1)),
sum(if (E <= 0, 0,1)),
sum(if( F <= 0, 0,1))
) FROM RESULT

C++ numbers add to a negative 
You need to change int to unsigned int or even better unsigned long long.
Your result is overflowing the maximum value of int on your system. Because
int is signed, when the most significant bit gets set, it becomes a
negative number. See the Stack Overflow question titled maximum value of
int, and this Swarthmore College page on binary arithmatic for more
information. If you're using Visual Studio, take a look at the Data Type
Ranges article on MSDN.
In addition to switching to unsigned long long, you should probably check
for overflow errors such as this and throw an exception. A revised version
of your code could look like this.
unsigned long long fib(int n) {
vector<unsigned long long> v;
v.push_back(1);
v.push_back(1);
for (int i = 2; i <= n; i++) {

Often big numbers become negative 
In mathematics numbers are infinite. However in computers they are not.
There is MAX_VALUE for each intlike type: int, short, long. For example
Integer.MAX_VALUE. When you try to increase number more than this value the
number becomes negative. This way the internal binary representation of
numbers work.
int i = Integer.MAX_VALUE;
i++; // i becomes negative.

Get negative numbers from expression 
Maybe you could try this one; it makes use of a lookbehind:
((?<=d)[+*/^()]?[d.]+)
I tested it here.
Basically, makes sure that there is a number before the operator to decide
what to match. So, if there is a digit before the operator, treat the
operator alone, otherwise, combine the minus with the digit.
EDIT: Separated the brackets from the lot, just in case (demo):
((?<=d)[+*/^][()]?[d.]+)

Negative Numbers in C# TextBox 
Instead of checking the length of the string (and discarding "" when it's
nonzero), you could check the cursor position and discard "" when the
cursor is not a the beginning or when there is already a "" at the
beginning.
But doing the whole check later during submission instead of swallowing
keystrokes might be better UX.

How to add Positives to negative numbers in php? 
Found my answer, seems like i have to just flip them
if($this>location['longitude'] < 0){ /* Flip if negative */
$minlong = $this>location['longitude']+$range;
$maxlong = $this>location['longitude']$range;
}else{
$minlong = $this>location['longitude']$range;
$maxlong = $this>location['longitude']+$range;
}
if($this>location['latitude'] < 0){ /* Flip if negative */
$minlat = $this>location['latitude']+$range;
$maxlat = $this>location['latitude']$range;
}else{
$minlat = $this>location['latitude']$range;
$maxlat = $this>location['latitude']+$range;
}

Highlight negative numbers in red 
Why don't you use if ( cellvalue < 0) {
$('td').each(function() {
var cellvalue = $(this).html();
if ( cellvalue < 0) {
$(this).wrapInner('<strong
class="colorred"></strong>');
}
});
EXAMPLE

str_repeat and negative numbers 
You're checking for $hearts <= 0, and then dropping through to a check
for $hearts <10, which is also true  that's where your error is.
Try this:
if(($hearts < 10) && ($hearts >0))
{
$health = str_repeat('♥', $hearts);
}

Shifting by Negative Numbers 
<< (and other shift operators) only takes 5 least significant bits of
its right operand for int, and 6 for long, because it makes no sense to
shift int by more than 31.
In your case it's 0b10110 = 22.
Therefore 1 << (10) is equivalent to 1 << 22.

How does Java calculate negative numbers? 
The assumption that the highest bit is a simple sign bit is wrong. Java, as
well as most modern programming languages (and hardware architectures) use
the socalled two's complement representation for numbers. (The bit itself,
coincidentally, does indicate the sign, but not in the way you would expect
it to, i.e. 150 and 150 have more differences than just the sign bit in
their representation.)
This representation might seem like an odd choice at first, but it actually
makes operations such as adding a positive number to a negative number (or
variations of this) automagically work, without making the processor have
to check for special cases.
According to the relevant Wikipedia article:
The system is useful in simplifying the implementation of arithmetic on
computer hardware. Adding

CompareValidator fails when both numbers are negative in ASP.NET 
You must spesify the Type to Integer, because the default data type is
String.
<asp:CompareValidator ID="CompareYears" runat="server"
Type="Integer"
ControlToValidate="Year2DropDown" ControlToCompare="Year1DropDown"
Operator="GreaterThanEqual" ErrorMessage="End date must be greater than or
equal to start date"></asp:CompareValidator>
