negative-number

ANTLR parsing and code generation with “-” operator and “-” number sign

岁酱吖の 提交于 2020-01-16 18:53:45
问题 This is my grammar: grammar FOOL; @header { import java.util.ArrayList; } @lexer::members { public ArrayList<String> lexicalErrors = new ArrayList<>(); } /*------------------------------------------------------------------ * PARSER RULES *------------------------------------------------------------------*/ prog : exp SEMIC #singleExp | let exp SEMIC #letInExp | (classdec)+ SEMIC (let)? exp SEMIC #classExp ; classdec : CLASS ID ( EXTENDS ID )? (LPAR (vardec ( COMMA vardec)*)? RPAR)? (CLPAR (

PHP Unsigned Right Shift - Malfunctioning

限于喜欢 提交于 2020-01-13 10:07:29
问题 So, when using my method to preform a ( >>> ) unsigned right shift in PHP, the result is incorrect when the numbers involve negatives. PHP Application Results: INPUT: 10 >>> 3 INPUT: -10 >>> 3 OUTPUT: 1 OUTPUT: 2684354558 JAVA APPLICATION RESULTS: INPUT: 10 >>> 3 INPUT: -10 >>> 3 OUTPUT: 1 OUTPUT: 536870910 (The top results are correct and generated by Java and then the bottom results are incorrect and generated by PHP) It's only when the number is negative in PHP that it fails. The shifts

Unsigned negative primitives?

房东的猫 提交于 2020-01-13 09:14:08
问题 In C++ we can make primitives unsigned . But they are always positive. Is there also a way to make unsigned negative variables? I know the word unsigned means "without sign", so also not a minus (-) sign. But I think C++ must provide it. 回答1: No. unsigned can only contain nonnegative numbers. If you need a type that only represent negative numbers, you need to write a class yourself, or just interpret the value as negative in your program. (But why do you need such a type?) 回答2: unsigned

Change NSNumberFormatter's negative format from (xxx.xx) to -xxx.xx

不问归期 提交于 2020-01-10 19:26:55
问题 I want to change my NSNumberformatter from displaying negative numbers with parenthesis around them to putting the minus sign in front (or whatever the localized standard is). I would assume I could do this with setNegativeFormat: but reading Apple's oh so thorough docs I am left scratching my head: setNegativeFormat: Sets the format the receiver uses to display negative values. - (void)setNegativeFormat:(NSString *)aFormat Parameters aFormat A string that specifies the format for negative

How to turn all numbers in a list into their negative counterparts?

时光毁灭记忆、已成空白 提交于 2020-01-09 11:07:26
问题 I am trying to turn a list of positive numbers into a list of negative numbers with the same value in python 3.3.3 For example turning [1,2,3] into [-1,-2,-3] I have this code: xamount=int(input("How much of x is there")) integeramount=int(input("How much of the integer is there")) a=1 lista=[] while(a<=integeramount): if(integeramount%a==0): lista.extend([a]) a=a+1 listb=lista print(listb) [ -x for x in listb] print(listb) This prints two identical lists when I want one to be positive and

How to turn all numbers in a list into their negative counterparts?

帅比萌擦擦* 提交于 2020-01-09 11:06:10
问题 I am trying to turn a list of positive numbers into a list of negative numbers with the same value in python 3.3.3 For example turning [1,2,3] into [-1,-2,-3] I have this code: xamount=int(input("How much of x is there")) integeramount=int(input("How much of the integer is there")) a=1 lista=[] while(a<=integeramount): if(integeramount%a==0): lista.extend([a]) a=a+1 listb=lista print(listb) [ -x for x in listb] print(listb) This prints two identical lists when I want one to be positive and

How to represent -0 in binary

半城伤御伤魂 提交于 2020-01-06 16:20:05
问题 This question concerns converting a floating point number that is less than abs(1) and negative to 32.32 format, for example: -0.1234. When this is converted to 32.32, the integer portion and fractional portion are separated into the upper and lower 32 bit words, respectively. In this example above, the upper 32-bits will hold -0, while the lower will hold .1234, both converted to binary. So the question is, in this case, how does one properly represent the -0 value in binary? 回答1: It depends

Why does the most negative int value cause an error about ambiguous function overloads?

纵饮孤独 提交于 2019-12-28 01:55:10
问题 I'm learning about function overloading in C++ and came across this: void display(int a) { cout << "int" << endl; } void display(unsigned a) { cout << "unsigned" << endl; } int main() { int i = -2147483648; cout << i << endl; //will display -2147483648 display(-2147483648); } From what I understood, any value given in the int range (in my case int is 4 byte) will call display(int) and any value outside this range will be ambiguous (since the compiler cannot decide which function to call). It

Rails range_field from 0 to -100

做~自己de王妃 提交于 2019-12-24 14:11:18
问题 I have a range field that, when slid right, needs to make the output "more negative" up to -100. Here's my current code: <%= f.range_field :Question1, :in => 0..-100, :step => '.1' %> Obviously, using :in => -100..0 works fine, but when I switch it to 0..-100, sliding to the right goes up to 100, which is clearly wrong. I need the user to be able to slide right in order to get a more negative number. Does anyone know how to make this happen? If this is not possible, is there a way to set up

Chisel UInt negative value error

雨燕双飞 提交于 2019-12-24 11:15:28
问题 I have recently started work in scala, and am required to create an implementation of MD5. It is my understanding that MD5 requires unsigned types, which scala does not come with. As I will soon begin Chisel, which does have unsigned types, I decided to implement its library. Everything appears good so far, except when doing the below bitwise operations, my F value becomes -271733879, which causes an error "Caused by: java.lang.IllegalArgumentException: requirement failed: UInt literal