operators

The Cash or Credit problem

If you go to a store and ask "Cash or Credit?" they might simply say "Yes." This doesn't tell you anything as you posed an OR statement. if(cash || credit) With humans it's possible that they might respond "Both" to that question, or "Only {cash | credit}." Is there a way (or operator) to force the a statement to return the TRUE portio...

Search object array for matching possible multiple values using different comparison operators

I have a function to search an array of objects for a matching value using the eq operator, like so: sub find { my ( $self, %params ) = @_; my @entries = @{ $self->{_entries} }; if ( $params{filename} ) { @entries = grep { $_->filename eq $params{filename} } @entries; } if ( $params{date} ) { @entrie...

With Ruby, where to use NOT, AND, OR, XOR operations for Fixnum or Bignum?

Hi, Just wondering if anyone has any realworld examples or know when you might use the NOT, AND, OR, XOR, <<, >> operators in Ruby. I've been programming for 4 years and never come across the need to use any of these, wondering how common actual usage is & if its something I should fully understand. Thanks, -J ...

(C++) What's the difference between these overloaded operator functions?

What is the difference between these two ways of overloading the != operator below. Which is consider better? Class Test { ...// private: int iTest public: BOOL operator==(const &Test test) const; BOOL operator!=(const &Test test) const; } BOOL operator==(const &Test test) const { return (iTest == test.iTest); } ...

overload Equals, is this wrong?

Reading some piece of code and I keep seeing this : public override bool Equals (object obj) { if (obj == null || this.GetType ().Equals (obj.GetType())) return false; //compare code... } Shouldn't it be like this (note the !): public override bool Equals (object obj) { if (obj == null || !this.GetType ().Equals (obj.G...

=& operator in PHP

Example: $this->sql =& new GuestBook_SQL; What does it do? ...

JSF Deferred EL conditional syntax problem

Hello I can't find any resources which can answer why I'm getting an error with this: oncomplete="#{MyBacking.oError ? #{rich:component('oErrorPanel')}.show() : return false;}" in a richfaces a4j:commandButton. oError is referring to a method in my bean called isOError. I'm getting the error SEVERE: Servlet.service() for servlet F...

when to use === operator check in JavaScript?

Possible Duplicate: Javascript === vs == : Does it matter which equal operator I use? As the title states; when should you use the === operator check when using JavaScript, and when not to. Edit: more complete answer found here. Thanks to Mark Byers for pointing it out. _L ...

what does ** mean in C

What does it mean when a object has 2 asterisks at the beginning? **variable ...

C#: How can I make an integer negative?

Hi, How can I make an integer negative in C#? abc = 5645307; // how to make abc -5645307 ? ...

How to change the meaning of pointer access operator

Hi All, This may be very obvious question, pardon me if so. I have below code snippet out of my project, #include <stdio.h> class X { public: int i; X() : i(0) {}; }; int main(int argc,char *arv[]) { X *ptr = new X[10]; unsigned index = 5; cout<<ptr[index].i<<endl; return 0; } Question Can I change the meaning of...

What pseudo-operators exist in Perl 5?

I am currently documenting all of Perl 5's operators (see the perlopref GitHub project) and I have decided to include Perl 5's pseudo-operators as well. To me, a pseudo-operator in Perl is anything that looks like an operator, but is really more than one operator or a some other piece of syntax. I have documented the four I am familiar...

Javascript ||, how to compare multiple variables value?

How to right this syntax correctly: if (tipoTropaPrioritaria[m] || troopsCount[m] || availableTroops[m]) == ("null" || "undefined") { ... } (to check if any of the first 3 variables is null or undefined) ...

Is it possible to pass arithmetic operators to a method in java?

Right now I'm going to have to write a method that looks like this: public String Calculate(String Operator, Double Operand1, Double Operand2) { if (Operator.equals("+")) { return String.valueOf(Operand1 + Operand2); } else if (Operator.equals("-")) { return String.valueOf...

Arithmetic operators and function calling in C

I'm not quite sure why I can't do double a = (double) my_Function(45) / 2048 / 2340 / 90; printf("%.4f",a); // prints out 0.00 But instead I have to use one more variable as: double a = (double) my_Function(45); double b = a / 2048 / 2340 / 90; printf("%.4f",b); // prints out the correct value ...

event.clientX is readonly?

Working in IE 8, mostly, but trying to write a portable solution for modern browsers. Using telerik controls. I'm catching the 'Showing' client-side event of the RadContextMenu and trying to adjust it's coordinates. The clientX, clientY and x,y members of the DOM event cannot be assigned a new value. Visual Studio breaks with a "htmlfi...

Dynamic Comparison Operators in PHP

Hi All Is it possible, in any way, to pass comparison operators as variables to a function? I am looking at producing some convenience functions, for example (and I know this won't work): function isAnd($var, $value, $operator = '==') { if(isset($var) && $var $operator $value) return true; } if(isAnd(1, 1, '===')) echo 'wo...

How do I define my own operators in the Io programming language?

I'm trying to define my own operator in Io, and I'm having a hard time. I have an object: MyObject := Object clone do( lst := list() !! := method(n, lst at(n)) ) But when I call it, like this: x := MyObject clone do(lst appendSeq(list(1, 2, 3))) x !! 2 But I get an exception that argument 0 to at must not be nil. How can I fix?...

Function should return reference or object?

Let's discuss these two functions: complex& operator+=(const T& val); complex operator+(const T& val); Where "complex" is a name of a class that implements for example complex variable. So first operator returnes reference in order to be possible to write a+=b+=c ( which is equivalent to b=b+c; a=a+b;). Second operator returnes and...

Is there an "opposite" to the null coalescing operator? (…in any language?)

null coalescing translates roughly to return x, unless it is null, in which case return y I often need return null if x is null, otherwise return x.y I can use return x == null ? null : x.y; Not bad, but that null in the middle always bothers me -- it seems superfluous. I'd prefer something like return x :: x.y;, where what follows th...