c++,c,multiplication,negative-number

Recommend to use what explains the code best, unless one is working with an old platform or compiler. In that case, use negation. Following are some obscure differences: int format with non-2's complement: In days of yore, a multiplication by of 0 and -1 could result in 0 yet a...

javascript,scroll,negative-number

Yes. Use Math.max(). It will return the largest of its arguments. sW = Math.max(0, sW); ...

textbox,vb6,legacy-code,negative-number

Apparently using a different font can fix it, in our case we made a custom font to alleviate the issue.

c++,floating-point,integer,rounding,negative-number

For C++ there is one: std::lround

swift,switch-statement,operators,negative-number

In the context of a switch case, a ... b is a "closed interval" and the start must be less or equal to the end of the interval. Also a plus or minus sign must be separated from ... by a space (or the number enclosed in parentheses), so both...

This is usually denoted as (x)+, sometimes also x⊔0 or x∨0, where the symbol alludes to the shape of the kinks in the maximum of two functions, for instance in |x|=max(x,-x). In Lebesgue integration theory, for example, a function is first split into its positive and negative part, so that...

reporting-services,graph,ssrs-2008,logarithm,negative-number

Not possible, apparently. Stupid math. Had to attach a Linear graph, y-scaled from 0 to -20, below the Log one. Grr.

php,regex,floating-point,negative-number

-?\d+(?:\.\d+)? This should do it for you. $re = "/-?\\d+(?:\\.\\d+)?/m"; $str = "4.321 -3.1212"; $subst = "coach"; $result = preg_replace($re, $subst, $str); ...

As a general rule, the modulo and division should satisfy the equation b * (a/b) + a%b == a For positive numbers, it is obvious that this means that a%b must be a positive number. But if a/b is negative, then the result is rounded towards zero. So take for...

Ok I found the way ! #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { float voltage,current1,current2; char voltages[20], current[20], dtm[100]; strcpy( dtm, "VOLTAGE 0.231023459 CURRENT -0.234334567 0.345511234"); sscanf( dtm, "%s %f %s %f %f", voltages,&voltage,current,¤t1, ¤t2); printf("voltage = %f \n",voltage); printf("current1 = %f \n",current1); printf("current2 = %f \n",current2); return(0);...

It depends on the machine you're targeting. On a machine that uses a 2's complement representation for integers there's no difference at bit-level between 0 and -0 (they have the same representation) If your machine used one's complement, you definitely could 0000 0000 -> signed 0 1111 1111 -> signed...

javascript,comparison,zero,negative-number

How do I test if a number is greater than or equal to positive zero (+0)? Check whether its reciprocal is positive: 1 / value > 0 The reciprocal of +0 is positive Infinity. The reciprocal of -0 is negative Infinity. UPDATE: The fact that diff can return +0...

io,verilog,fwrite,fread,negative-number

An example for writing signed number to a text file using fwrite : module write_signed; integer out_file; initial begin out_file = $fopen("out_file.txt","w"); $fwrite(out_file, "%d\n", 3); $fwrite(out_file, "%d\n", 2); $fwrite(out_file, "%d\n", 1); $fwrite(out_file, "%d\n", 0); $fwrite(out_file, "%d\n", -1); $fwrite(out_file, "%d\n", -2); $fclose(out_file); end endmodule Which generates : 3 2 1 0...

I think maybe somewhere else is wrong in your code, here is a sample which is similar to yours and it is working. Did you include the correct headers? #include "ctype.h" #include "stdlib.h" #include "stdio.h" int main () { char op[30]; fgets(op, sizeof(op), stdin); /* input -11 */ printf("%s\n", op);...

python,bit-manipulation,negative-number

For an unsigned character, you'd want to use the B format character, not b (see Format Characters section in the struct module documentation. Since unpack() always returns a tuple of values, even if only one is specified by the format string, a [0] can be added to the end of...

javascript,arrays,modulo,negative-number

You can use n integer n % l integer in (-l, l) n % l + l integer in (0, 2*l) (n % l + l) % l integer in [0, l) In JavaScript, arr[(someInteger % arr.length + arr.length) % arr.length] Alternatively, you can play with flooring, ceiling and truncating:...

c#,parsing,timespan,negative-number

If "negative" values always have - before each component, you can look for the sign and use two different format strings: TimeSpan ts; string s = "-4:-41:-4.102276"; if(s.StartsWith("-")) ts = -TimeSpan.ParseExact(s, @"\-h\:\-m\:\-s\.ffffff", enUS); else ts = TimeSpan.ParseExact(s, @"h\:m\:s\.ffffff", enUS); ...

objective-c,ios8,xcode6,negative-number,arc4random

arc4random() return type is an u_int32_t which is an unsigned int so it can't directly return a negative number. You will need to 'manipulate' it in order to receive a positive or negative range. First, I would like to suggest to use arc4random_uniform() instead of arc4random() % since it avoids...

python,python-2.7,math,negative-number,exponentiation

Python is correct and doing what you would expect it to do. It is a matter of order of operations. ANY number (negative or positive) to zeroth power is equal to 1. But keep in mind also that multiplication comes before subtraction in order of operations. So in more detail,...

python-2.7,range,negative-number

Range() can take two parameters: range(start, end), where start is inclusive, and end is exclusive. So the range you want for 3 is: range(-3, 4). To make it general: s = int(input("Enter a number ")) for i in range(-s, s+1): print i ...

c,concatenation,subtraction,negative-number

OP's method of getting time is flawed. It retrieves the second and microsecond from 2 calls, yet time elapses between the 2 calls and the numbers of seconds could have incremented. Instead, re-write ClockGetTime() to get both sec and microsec. // time_t time_1_sec = time(NULL); // uint32_t client_1_sec = time_1_sec;...

javascript,math,negative-number

Simply try now = now - num/2; instead of your if... statement. This corresponds to the mapping now |--> now - 90/2 which has a range of [-45,45] when now has a domain of [0,90]....

c,int,hex,bit-fields,negative-number

%x prints the hex representation of the value of the given argument. The two's complement representation of -1, in hex, gives you that ffffffff. FWIW: This outcome is not particularly related to use of bit-filed variable here, as printf() is a variadic function....

twitter-bootstrap-3,integer,asp.net-mvc-5,spinner,negative-number

By spinner if you mean an input field, then it is an HTML5 utility, not Bootstrap's. <input type="number"> Above code will give you a spinner....

mysql,negative-number,comparison-operators

The easiest solution is of course to use a DECIMAL() or FLOAT column in the table. Since you are working with VARCHAR() types and prefer to continue working with VARCHAR, the RDBMS is not correctly treating () enclosed values as negatives, and instead attempting to cast the strings to an...

c,binary,decimal,negative-number

decimal and int b[s] not initialized. By not initializing decimal to 0, it might have the value of 0 on a machine one day and quite different results otherwise. void decTobin(int dec, int s) { // while loop does not set all `b`,but following for loop uses all `b` //...

php,floating-point,printf,number-formatting,negative-number

I guess your numbers are saved as a string, so in order to get your output you just simple cast them to a float or double like this: echo (float) $number; For more information about casting see the manual: http://php.net/manual/en/language.types.type-juggling.php#language.types.typecasting...

arrays,elements,negative-number

There are two answers here. First is the answer to your code. You must properly format an array. System.out.println(Arrays.toString(array1)); The second answer is just another approach to your problem. It's a bit cleaner and more efficient, and at least checks to make sure your array is longer than 1 before...