Search Results

Search found 977 results on 40 pages for 'operators'.

Page 6/40 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • 48-bit bitwise operations in Javascript?

    - by randomhelp
    I've been given the task of porting Java's Java.util.Random() to JavaScript, and I've run across a huge performance hit/inaccuracy using bitwise operators in Javascript on sufficiently large numbers. Some cursory research states that "bitwise operators in JavaScript are inherently slow," because internally it appears that JavaScript will cast all of its double values into signed 32-bit integers to do the bitwise operations (see https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Operators/Bitwise_Operators for more on this.) Because of this, I can't do a direct port of the Java random number generator, and I need to get the same numeric results as Java.util.Random(). Writing something like this.next = function(bits) { if (!bits) { bits = 48; } this.seed = (this.seed * 25214903917 + 11) & ((1 << 48) - 1); return this.seed >>> (48 - bits); }; (which is an almost-direct port of the Java.util.Random()) code won't work properly, since Javascript can't do bitwise operations on an integer that size.) I've figured out that I can just make a seedable random number generator in 32-bit space using the Lehmer algorithm, but the trick is that I need to get the same values as I would with Java.util.Random(). What should I do to make a faster, functional port?

    Read the article

  • Purpose of overloading operators in C++?

    - by Geo Drawkcab
    What is the main purpose of overloading operators in C++? In the code below, << and >> are overloaded; what is the advantage to doing so? #include <iostream> #include <string> using namespace std; class book { string name,gvari; double cost; int year; public: book(){}; book(string a, string b, double c, int d) { a=name;b=gvari;c=cost;d=year; } ~book() {} double setprice(double a) { return a=cost; } friend ostream& operator <<(ostream& , book&); void printbook(){ cout<<"wignis saxeli "<<name<<endl; cout<<"wignis avtori "<<gvari<<endl; cout<<"girebuleba "<<cost<<endl; cout<<"weli "<<year<<endl; } }; ostream& operator <<(ostream& out, book& a){ out<<"wignis saxeli "<<a.name<<endl; out<<"wignis avtori "<<a.gvari<<endl; out<<"girebuleba "<<a.cost<<endl; out<<"weli "<<a.year<<endl; return out; } class library_card : public book { string nomeri; int raod; public: library_card(){}; library_card( string a, int b){a=nomeri;b=raod;} ~library_card() {}; void printcard(){ cout<<"katalogis nomeri "<<nomeri<<endl; cout<<"gacemis raodenoba "<<raod<<endl; } friend ostream& operator <<(ostream& , library_card&); }; ostream& operator <<(ostream& out, library_card& b) { out<<"katalogis nomeri "<<b.nomeri<<endl; out<<"gacemis raodenoba "<<b.raod<<endl; return out; } int main() { book A("robizon kruno","giorgi",15,1992); library_card B("910CPP",123); A.printbook(); B.printbook(); A.setprice(15); B.printbook(); system("pause"); return 0; }

    Read the article

  • VIM: created syntax not showing up?

    - by joxnas
    HI people I recently changed to VIM for coding in C. I'd like to hightlight the operators +-<=& ... etc I searched in google how should i do it, and i found the answer in this website: I was suppose to do something like: syntax match Operadores /[][><()&!|+*={}-]/ hi Operadores guifg=#000000 gui=BOLD Those characters were supposed to appear as black, bold characters. However, that doesn't happen when I open my .C files. However, if I create a newfile, (where there the C syntax doesn't show up), I am able to see the black, bolded operators. How can i correct this situation, and why is this happening (it seams like if my syntax is beeing overwrided by the C syntax). I'm using gvim, and this is my vimrc: colorscheme nicotine set smartindent set number set guifont=Inconsolata\ Medium\ 11 set numberwidth=5 noremap j jzz noremap k kzz Thanks, any help is appreciated. (And dont forget I'm a novice in VIM, and ..sorry for my English)

    Read the article

  • Consistency in placing operator functions

    - by wrongusername
    I have a class like this: class A { ...private functions, variables, etc... public: ...some public functions and variables... A operator * (double); A operator / (double); A operator * (A); ...and lots of other operators } However, I want to also be able to do stuff like 2 * A instead of only being allowed to do A * 2, and so I would need functions like these outside of the class: A operator * (double, A); A operator / (double, A); ...etc... Should I put all these operators outside of the class for consistency, or should I keep half inside and half outside?

    Read the article

  • Are there real world applications where the use of prefix versus postfix operators matters?

    - by Kenneth
    In college it is taught how you can do math problems which use the ++ or -- operators on some variable referenced in the equation such that the result of the equation would yield different results if you switched the operator from postfix to prefix or vice versa. Are there any real world applications of using postfix or prefix operator where it makes a difference as to which you use? It doesn't seem to me (maybe I just don't have enough experience yet in programming) that there really is much use to having the different operators if it only applies in math equations. EDIT: Suggestions so far include: function calls //f(++x) != f(x++) loop comparison //while (++i < MAX) != while (i++ < MAX)

    Read the article

  • Overloading the QDataStream << and >> operators for a user-defined type

    - by Alex Wood
    I have a an object I'd like to be able to read and write to/from a QDataStream. The header is as follows: class Compound { public: Compound(QString, QPixmap*, Ui::MainWindow*); void saveCurrentInfo(); void restoreSavedInfo(QGraphicsScene*); void setImage(QPixmap*); QString getName(); private: QString name, homeNotes, addNotes, expText; Ui::MainWindow *gui; QPixmap *image; struct NMRdata { QString hnmrText, cnmrText, hn_nmrText, hn_nmrNucl, notes; int hnmrFreqIndex, cnmrFreqIndex, hn_nmrFreqIndex, hnmrSolvIndex, cnmrSolvIndex, hn_nmrSolvIndex; }*nmr_data; struct IRdata { QString uvConc, lowResMethod, irText, uvText, lowResText, highResText, highResCalc, highResFnd, highResFrmla, notes; int irSolvIndex, uvSolvIndex; }*ir_data; struct PhysicalData { QString mpEdit, bpEdit, mpParensEdit, bpParensEdit, rfEdit, phyText, optAlpha, optConc, elemText, elemFrmla, notes; int phySolvIndex, optSolvIndex; }*physical_data; }; For all intensive purposes, the class just serves as an abstraction for a handful of QStrings and a QPixmap. Ideally, I would be able to write a QList to a QDataStream but I'm not exactly sure how to go about doing this. If operator overloading is a suitable solution, would writing code like friend QDataStream& operator << (QDataStream&,Compound) { ... } be a potential solution? I'm very open to suggestions! Please let me know if any further clarification is needed.

    Read the article

  • Strlen of MAX 16 chars string using bitwise operators

    - by fabrizioM
    The challenge is to find the fastest way to determine in C/C++ the length of a c-string using bitwise operations in C. char thestring[16]; The c-string has a max size of 16 chars and is inside a buffer If the string is equal to 16 chars doesn't have the null byte at the end. I am sure can be done but didn't got it right yet. I am working on this at the moment, but assuming the string is memcpied on a zero-filled buffer. len = buff[0] != 0x0 + buff[1] != 0x0 + buff[2] != 0x0 + buff[3] != 0x0 + buff[4] != 0x0 + buff[5] != 0x0 + buff[6] != 0x0 + buff[7] != 0x0 + buff[8] != 0x0 + buff[9] != 0x0 + buff[10] != 0x0 + buff[11] != 0x0 + buff[12] != 0x0 + buff[13] != 0x0 + buff[14] != 0x0 + buff[15] != 0x0;

    Read the article

  • Binary comparison operators on generic types

    - by Brian Triplett
    I have a generic class that takes a type T. Within this class I have a method were I need to compare a type T to another type T such as: public class MyClass<T> { public T MaxValue { // Implimentation for MaxValue } public T MyMethod(T argument) { if(argument > this.MaxValue) { // Then do something } } } The comparison operation inside of MyMethod fails with Compiler Error CS0019. Is it possible to add a constraint to T to make this work? I tried adding a where T: IComparable<T> to the class definition to no avail.

    Read the article

  • NetBeans Java code formatter: logical operators on new line

    - by mizipzor
    My code looks like this: if (firstCondition() && secondCondition()) { // ... code } The default settings for the code formatter in NetBeans wants to put the && on a new line, like this: if (firstCondition() && secondCondition()) { // ... code } The formatter works well so I would just like to find the setting so it doesnt change the code to the latter. Whats the setting called?

    Read the article

  • Comparison operators not supported for type IList when Paging data in Linq to Sql

    - by Dan
    I can understand what the error is saying - it can't compare a list. Not a problem, other than the fact that I don't know how to not have it compare a list when I want to page through a model with a list as a property. My Model: Event : IEvent int Id string Title // Other stuff.. LazyList<EventDate> Dates // The "problem" property Method which pages the data (truncated): public JsonResult JsonEventList(int skip, int take) { var query = _eventService.GetEvents(); // Do some filtering, then page data.. query = query.Skip(skip).Take(take); return Json(query.ToArray()); } As I said, the above is truncated quite a bit, leaving only the main point of the function: filter, page and return JSON'd data. The exception occurs when I enumerate (.ToArray()). The Event object is really only used to list the common objects of all the event types (Meetings, Birthdays, etc - for example). It still implements IEvent like the other types, so I can't just remove the LazyList<EventDate> Dates' property unless I no longer implementIEvent` Anyway, is there a way to avoid this? I don't really want to compare a LazyList when I page, but I do not know how to resolve this issue. Thank you in advance! :)

    Read the article

  • templates and casting operators

    - by Jonathan Swinney
    This code compiles in CodeGear 2009 and Visual Studio 2010 but not gcc. Why? class Foo { public: operator int() const; template <typename T> T get() const { return this->operator T(); } }; Foo::operator int() const { return 5; } The error message is: test.cpp: In member function `T Foo::get() const': test.cpp:6: error: 'const class Foo' has no member named 'operator T'

    Read the article

  • Objective c key path operators @avg,@max .....

    - by davide
    arr = [[NSMutableArray alloc]init]; [arr addObject:[NSNumber numberWithInt:4]]; [arr addObject:[NSNumber numberWithInt:45]]; [arr addObject:[NSNumber numberWithInt:23]]; [arr addObject:[NSNumber numberWithInt:12]]; NSLog(@"The avg = %@", [arr valueForKeyPath:@"@avg.intValue"]); This code works fine, but why? valueForKeyPath:@"@avg.intValue" is requesting (int) from each NSNumber, but we are outputting a %@ string in the log. If i try to output a decimal %d i get a number that possibly is a pointer to something. Can somebody explain why the integers become NSNumbers when i call the @avg operator?

    Read the article

  • Optimize conditional operators branching in C#

    - by abatishchev
    Hello. I have next code: return this.AllowChooseAny.Value ? radioSpecific.Checked ? UserManager.CurrentUser.IsClient ? txtSubject.Text : subjectDropDownList.SelectedItem.Text : String.Empty : UserManager.CurrentUser.IsClient ? txtSubject.Text : subjectDropDownList.SelectedItem.Text; or in less complex form: return any ? specified ? isClient ? textbox : dropdown : empty : isClient ? textbox : dropdown; or in schematic form: | any / \ specified isClient / \ / \ isClient empty textbox dropdown / \ textbox dropdown Evidently I have a duplicated block on two different levels. Is it possible to optimize this code to probably split them to one? Or something like that..

    Read the article

  • The use of mod operators in ada

    - by maddy
    Hi all, Can anyone please tell me the usage of the following declarations shown below.I am a beginner in ada language.I had tried the internet but that was not clear enough. type Unsigned_4 is mod 2 ** 4; for Unsigned_4'Size use 4;

    Read the article

  • Sikuli List of Functions & Operators

    - by PPTim
    Hello, I've just discovered Sikuli, and would like to see a comprehensive functions list without digging through the online-examples and demos. Has anyone found such a list? Furthermore, apparently Sikuli supports more complex loops and function calls as well, and seems to be based in Python(!!). Examples would be great. Thanks.

    Read the article

  • How to implement == or >= operators for generic type

    - by momsd
    I have a generic type Foo which has a internal generic class Boo. Boo class a property Value of type K. In a method inside Foo i want to do a boo.Value >= value Note that second operand value is of type T. while compiling i am getting following error: Operator '=' cannot be applied to operands of type 'T' and 'T' Can anyone please tell me whats the problem here?

    Read the article

  • C++ Implicit Conversion Operators

    - by Imbue
    I'm trying to find a nice inheritance solution in C++. I have a Rectangle class and a Square class. The Square class can't publicly inherit from Rectangle, because it cannot completely fulfill the rectangle's requirements. For example, a Rectangle can have it's width and height each set separately, and this of course is impossible with a Square. So, my dilemma. Square obviously will share a lot of code with Rectangle; they are quite similar. For examlpe, if I have a function like: bool IsPointInRectangle(const Rectangle& rect); it should work for a square too. In fact, I have a ton of such functions. So in making my Square class, I figured I would use private inheritance with a publicly accessible Rectangle conversion operator. So my square class looks like: class Square : private Rectangle { public: operator const Rectangle&() const; }; However, when I try to pass a Square to the IsPointInRectangle function, my compiler just complains that "Rectangle is an inaccessible base" in that context. I expect it to notice the Rectangle operator and use that instead. Is what I'm trying to do even possible? If this can't work I'm probably going to refactor part of Rectangle into MutableRectangle class. Thanks.

    Read the article

  • Lazy evaluation with ostream C++ operators

    - by SavinG
    I am looking for a portable way to implement lazy evaluation in C++ for logging class. Let's say that I have a simple logging function like void syslog(int priority, const char *format, ...); then in syslog() function we can do: if (priority < current_priority) return; so we never actually call the formatting function (sprintf). On the other hand, if we use logging stream like log << LOG_NOTICE << "test " << 123; all the formating is always executed, which may take a lot of time. Is there any possibility to actually use all the goodies of ostream (like custom << operator for classes, type safety, elegant syntax...) in a way that the formating is executed AFTER the logging level is checked ?

    Read the article

  • Can I create ternary operators in C# ?

    - by Scott S
    I want to create a ternary operator for a < b < c which is a < b && b < c. or any other option you can think of that a < b c and so on... I am a fan of my own shortform and I have wanted to create that since I learned programming in high school. How?

    Read the article

  • In Python, are there builtin functions for elementwise map of boolean operators over tuples of lists

    - by bshanks
    For example, if you have n lists of bools of the same length, then elementwise boolean AND should return another list of that length that has True in those positions where all the input lists have True, and False everywhere else. It's pretty easy to write, i just would prefer to use a builtin if one exists (for the sake of standardization/readability). Here's an implementation of elementwise AND: def eAnd(*args): return [all(tuple) for tuple in zip(*args)] example usage: >>> eAnd([True, False, True, False, True], [True, True, False, False, True], [True, True, False, False, True]) [True, False, False, False, True] thx

    Read the article

  • C++ STL question related to insert iterators and overloaded operators

    - by rshepherd
    #include <list> #include <set> #include <iterator> #include <algorithm> using namespace std; class MyContainer { public: string value; MyContainer& operator=(const string& s) { this->value = s; return *this; } }; int main() { list<string> strings; strings.push_back("0"); strings.push_back("1"); strings.push_back("2"); set<MyContainer> containers; copy(strings.begin(), strings.end(), inserter(containers, containers.end())); } The preceeding code does not compile. In standard C++ fashion the error output is verbose and difficult to understand. The key part seems to be this... /usr/include/c++/4.4/bits/stl_algobase.h:313: error: no match for ‘operator=’ in ‘__result.std::insert_iterator::operator* [with _Container = std::set, std::allocator ]() = __first.std::_List_iterator::operator* [with _Tp = std::basic_string, std::allocator ]()’ ...which I interpet to mean that the assignment operator needed is not defined. I took a look at the source code for insert_iterator and noted that it has overloaded the assignment operator. The copy algorithm must uses the insert iterators overloaded assignment operator to do its work(?). I guess that because my input iterator is on a container of strings and my output iterator is on a container of MyContainers that the overloaded insert_iterator assignment operator can no longer work. This is my best guess, but I am probably wrong. So, why exactly does this not work and how can I accomplish what I am trying to do?

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >