Search Results

Search found 2819 results on 113 pages for 'conditional expressions'.

Page 24/113 | < Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >

  • Why does the Ternary\Conditional operator seem significantly faster

    - by Jodrell
    Following on from this question, which I have partially answered. I compile this console app in x64 Release Mode, with optimizations on, and run it from the command line without a debugger attached. using System; using System.Diagnostics; class Program { static void Main() { var stopwatch = new Stopwatch(); var ternary = Looper(10, Ternary); var normal = Looper(10, Normal); if (ternary != normal) { throw new Exception(); } stopwatch.Start(); ternary = Looper(10000000, Ternary); stopWatch.Stop(); Console.WriteLine( "Ternary took {0}ms", stopwatch.ElapsedMilliseconds); stopwatch.Start(); normal = Looper(10000000, Normal); stopWatch.Stop(); Console.WriteLine( "Normal took {0}ms", stopwatch.ElapsedMilliseconds); if (ternary != normal) { throw new Exception(); } Console.ReadKey(); } static int Looper(int iterations, Func<bool, int, int> operation) { var result = 0; for (int i = 0; i < iterations; i++) { var condition = result % 11 == 4; var value = ((i * 11) / 3) % 5; result = operation(condition, value); } return result; } static int Ternary(bool condition, in value) { return value + (condition ? 2 : 1); } static int Normal(int iterations) { if (condition) { return = 2 + value; } return = 1 + value; } } I don't get any exceptions and the output to the console is somthing close to, Ternary took 107ms Normal took 230ms When I break down the CIL for the two logical functions I get this, ... Ternary ... { : ldarg.1 // push second arg : ldarg.0 // push first arg : brtrue.s T // if first arg is true jump to T : ldc.i4.1 // push int32(1) : br.s F // jump to F T: ldc.i4.2 // push int32(2) F: add // add either 1 or 2 to second arg : ret // return result } ... Normal ... { : ldarg.0 // push first arg : brfalse.s F // if first arg is false jump to F : ldc.i4.2 // push int32(2) : ldarg.1 // push second arg : add // add second arg to 2 : ret // return result F: ldc.i4.1 // push int32(1) : ldarg.1 // push second arg : add // add second arg to 1 : ret // return result } Whilst the Ternary CIL is a little shorter, it seems to me that the execution path through the CIL for either function takes 3 loads and 1 or 2 jumps and a return. Why does the Ternary function appear to be twice as fast. I underdtand that, in practice, they are both very quick and indeed, quich enough but, I would like to understand the discrepancy.

    Read the article

  • Pattern matching for lambda expressions

    - by alphomega
    21 --Primitive recursion constructor 22 pr :: ([Int] -> Int) -> ([Int] -> Int) -> ([Int] -> Int) 23 pr f g = \xs 0 -> f xs 24 pr f g = \xs (y+1) -> g xs y ((pr f g) xs y) I want the function this function creates to act differently on different inputs, so that it can create a recursive function. As expected, the above code doesn't work. How do I do something like pattern matching, but for the function it creates? Thanks

    Read the article

  • regular expressions: ignoring certain chars globally

    - by shi kui
    Consider it that '_'s in a number doesn't change that number's value so 1000==1_000==10_00. The Problem: given numbers like 1_244_23 1412_2 1_1111 etc..., how could I decide whether certain number appears in that collection? For example: 1244_23 yes, 11_111 yes, 1412_1 no. How could using regex to solve this? I mean, if I could tell the regex engine just ignore these '_''s when matching then this problem becomes trivial? How could I do so?

    Read the article

  • Are Conditional subquery

    - by Tobias Schulte
    I have a table foo and a table bar, where each foo might have a bar (and a bar might belong to multiple foos). Now I need to select all foos with a bar. My sql looks like this SELECT * FROM foo f WHERE [...] AND ($param IS NULL OR (SELECT ((COUNT(*))>0) FROM bar b WHERE f.bar = b.id)) with $param being replaced at runtime. The question is: Will the subquery be executed even if param is null, or will the dbms optimize the subquery out?

    Read the article

  • Conditional themes in Visual Studio 2008

    - by Bala R
    Can I have different visual studio themes associated to different solutions? Here's my problem. I have two files with sames names that have almost identical contents from two different solutions, open simultaneously. Of course, I have the first solution open and the file from the second solution is opened from explorer and has no connection to the first solution what so ever. Is there any way I can distinguish the the file that belongs to the solution from the other file, just by a different tab color or something like that and without hovering over the tab to look up the path. Thanks

    Read the article

  • How to create a conditional measure in SQL Server 2008 Analysis services

    - by Jonathan
    Hi there I am not sure if the title has the correct terms, I have a developer and am very new to cubes. I have a cube which has data associated to materials that are broken down into chemical compounds. For example a rock material has 10% of this chemical and 10% of that chemical, etc. Samples are taken daily and sample is a dimension with date, etc. So, the measure needs to average by the sample dimension but needs to sum across the chemical compound dimension (To add up to 100% for example). Is this at all possible?

    Read the article

  • Conditional deserialization

    - by Yordan Pavlov
    I am still not sure whether the title of my question is correct and it most probably is not. However I have spent some time searching both the net and stackoverflow and I can not find a good description of the issue I am facing. Basically what I want to achieve is the ability to read some raw bytes and based on the value of some of them to interpret the rest in different ways. This is how TLV works in a way, you check the tag and depending on it - interpret the result. Of course I can always keep that logic in my C++ code, however I am looking for a solution which would move the logic out of the source code (maybe to some xml description). This would allow me to describe different encodings (protocols) more easily. I am familiar with Protocol Buffers and some other serialization libraries, however all of them solve different issue. They assume they are on both ends of the communication, while I want to describe the communication (sort of). Is such solution available, if no - why not? Are there some inherent difficulties I will face trying to implement it.

    Read the article

  • Conditional formatting in Access

    - by every_answer_gets_a_point
    I have a datasheet that looks like this: ID name_ 1 2 3 4 1 name1 x 0 0 0 2 name2 0 x 0 0 3 name3 0 0 x 0 4 name4 0 0 0 x I have rectangles on a report that correspond to this datasheet. When the report opens, I need the rectangles to be colored red according to the data. For example, in the name1 row where there is an x in the 1 column, I need the specific rectangle corresponding to this (name1, 1) to be colored red. Here is the result that I need: x x x x (where x is a rectangle that is red) Perhaps the best place to place this code would be in ON LOAD event of the report, but i am not sure exactly. Can you please suggest to me some code that would turn the specified rectangles red according to the data?

    Read the article

  • parsing of mathematical expressions

    - by gcc
    (in c90) (linux) input: sqrt(2 - sin(3*A/B)^2.5) + 0.5*(C*~(D) + 3.11 +B) a b /*there are values for a,b,c,d */ c d input: cos(2 - asin(3*A/B)^2.5) +cos(0.5*(C*~(D)) + 3.11 +B) a b /*there are values for a,b,c,d */ c d input: sqrt(2 - sin(3*A/B)^2.5)/(0.5*(C*~(D)) + sin(3.11) +ln(B)) /*max lenght of formula is 250 characters*/ a b /*there are values for a,b,c,d */ c /*each variable with set of floating numbers*/ d As you can see infix formula in the input depends on user. My program will take a formula and n-tuples value. Then it calculate the results for each value of a,b,c and d. If you wonder I am saying ;outcome of program is graph. /sometimes,I think i will take input and store in string. then another idea is arise " I should store formula in the struct" but i don't know how I can construct the code on the base of structure./ really, I don't know way how to store the formula in program code so that I can do my job. can you show me? /* a,b,c,d is letters cos,sin,sqrt,ln is function*/

    Read the article

  • perl regular expressions substitution/replacement using variables with special characters

    - by user961627
    Okay I've checked previous similar questions and I've been juggling with different variations of quotemeta but something's still not right. I have a line with a word ID and two words - the first is the wrong word, the second is right. And I'm using a regex to replace the wrong word with the right one. $line = "ANN20021015_0104_XML_16_21 A$xAS A$xASA"; @splits = split("\t",$line); $wrong_word = quotemeta $splits[1]; $right_word = quotemeta $splits[2]; print $right_word."\n"; print $wrong_word."\n"; $line =~ s/$wrong_word\t/$right_word\t/g; print $line; What's wrong with what I'm doing? Edit The problem is that I'm unable to retain the complete words - they get chopped off at the special characters. This code works perfectly fine for words without special characters. The output I need for the above example is: ANN20021015_0104_XML_16_21 A$xASA A$xASA But what I get is ANN20021015_0104_XML_16_21 A A Because of the $ character.

    Read the article

  • Changing type of object in a conditional

    - by David Doria
    I'm having a bit of trouble with dynamic_casting. I need to determine at runtime the type of an object. Here is a demo: include include class PersonClass { public: std::string Name; virtual void test(){}; //it is annoying that this has to be here... }; class LawyerClass : public PersonClass { public: void GoToCourt(){}; }; class DoctorClass : public PersonClass { public: void GoToSurgery(){}; }; int main(int argc, char *argv[]) { PersonClass* person = new PersonClass; if(true) { person = dynamic_cast(person); } else { person = dynamic_cast(person); } person-GoToCourt(); return 0; } I would like to do the above. The only legal way I found to do it is to define all of the objects before hand: PersonClass* person = new PersonClass; LawyerClass* lawyer; DoctorClass* doctor; if(true) { lawyer = dynamic_cast(person); } else { doctor = dynamic_cast(person); } if(true) { lawyer-GoToCourt(); } The main problem with this (besides having to define a bunch of objects that won't be use) is that I have to change the name of the 'person' variable. Is there a better way? (I am not allowed to change any of the classes (Person, Lawyer, or Doctor) because they are part of a library that people who will use my code have and won't want to change). Thanks, Dave

    Read the article

  • Conditional Join In LINQ?

    - by Soo
    I am trying to write a query that grabs information from one database and joins it to information in a different database. TableA idA valueA idB TableB idB valueB The tricky part is that in TableA, idB isn't always defined, so when I do a normal join, I only get results where TableA has a idB value. What I want is to be able to grab all of the information from TableA even if it doesn't have a corresponding idB value.

    Read the article

  • Conditional interface programming for iPad?

    - by Fyrian
    Hi everyone! I'm working on an app for the iPad and am a little over my head with one issue. Is it possible to build an app for iPad that uses a function to control which interface layout is displayed? Something like "if these parameters are met, use XIB file "a" else use XIB file "b". I know that's not in any kind of legitimate format, but you get the idea. If this is possible, does anyone know of any tutorials on how to do it or sample code I could look at? Thanks!

    Read the article

  • XPath conditional text node selection

    - by Reinderien
    Hi there. I need to construct an xpath string to select all descendants of a certain table with these conditions: The table is a descendant of a form with a specific action attribute value. The selected descendants are text nodes. The text node content can only contain whitespace. It'll probably look something like: //form[@action = "submit.html"]//table//text()[ ...? ] Any tips would be appreciated. Thanks. Edit: For clarity, here is my current (working) compromise: function KillTextNodes(rootpath) { XPathIterate(rootpath + '//text()', function(node) { var tagname = node.parentNode.tagName; if (tagname != 'OPTION' && tagname != 'TH') Kill(node); }); }

    Read the article

  • Only assignment, call, increment, decrement, and new object expressions can be used as a statement : Messagebox

    - by Nuru Salihu
    This what i am trying to achieved if(this.BeginInvoke((Action)(() => MessageBox.Show("Test", MessageBoxButtons.YesNo) == DialogResult.No))) The above gives error. I try seperating the delegate to an outside method like delegate void test(string text); private void SetTest(string text) { if(MessageBox.Show(text,"", MessageBoxButtons.YesNo) == DialogResult.No) } But it breach the very reason why i need the delegate. I found out the first works for me but i don't know how to put it in an if/else statement. Pls any help in a better way i can achieve some thing like below would be appreciated. if(this.BeginInvoke((Action)(() => MessageBox.Show("Test", MessageBoxButtons.YesNo) == DialogResult.No)))

    Read the article

  • Creating Delegates With Lambda Expressions in F#

    - by Matt H
    Why does... type IntDelegate = delegate of int -> unit type ListHelper = static member ApplyDelegate (l : int list) (d : IntDelegate) = l |> List.iter (fun x -> d.Invoke x) ListHelper.ApplyDelegate [1..10] (fun x -> printfn "%d" x) not compile, when: type IntDelegate = delegate of int -> unit type ListHelper = static member ApplyDelegate (l : int list, d : IntDelegate) = l |> List.iter (fun x -> d.Invoke x) ListHelper.ApplyDelegate ([1..10], (fun x -> printfn "%d" x)) does? The only difference that is that in the second one, ApplyDelegate takes its parameters as a tuple. Error 1 This function takes too many arguments, or is used in a context where a function is not expected

    Read the article

  • Float conditional in bash

    - by Werner
    Hi, in bash I need to compare two float numbers, one which I define in the script and the other read as paramter, for that I do: if [[ $aff -gt 0 ]] then a=b echo "xxx "$aff #echo $CX $CY $CZ $aff fi but I get the error: [[: -309.585300: syntax error: invalid arithmetic operator (error token is ".585300") What is wrong? Thanks

    Read the article

  • Conditional directive to identify C++ Builder personalities

    - by Narcís Calvet
    Hello, I have a Delphi component which I want to install and have it available at the component palette in Delphi but not in C++ Builder. In BDS/RAD 2006 and above I can either have it installed for both personalities or none. I need to do so because this component uses 3rd party libraries that doesn't support C++ Builder. I have looked at jedi.inc mentioned here but I'm not able to find the combination to be able to register the component in Delphi personalities only. The component should also work for D5, D6 and D7 but not for BCB5 and BCB6. Is this possible? BTW: Component is written in Delphi. C++ Builder shares same packages as Delphi. Thanks in advance.

    Read the article

  • C# array of objects - conditional validation

    - by fishdump
    Sorry about the vague title! I have an class with a number of member variables (system, zone, site, ...) public sealed class Cello { public String Company; public String Zone; public String System; public String Site; public String Facility; public String Process; //... } I have an array of objects of this class. private Cello[] m_cellos = null; // ... I need to know whether the array contains objects with the same site but different systems, zones or companies since such a situation would be illegal. I have various other checks to make but they are all along similar lines. The Array class has a number of functions that look promising but I am not very up on defining 'key selector' functions and things like that. Any suggestions or pointers would be greatly appreciated. --- Alistair.

    Read the article

  • Conditional value for ActiveRecord create method only

    - by Steve Wright
    I have a form where I have an administrator creating new users. The form uses the User model I created (login, password, first_name, etc...). For the last field on the form, I want to have a checkbox that doesn't need to be stored as part of the User record, but it is needed for the controller. This will control whether or not the newly created user will receive a welcome email or not. def create @user = User.new(params[:user]) if @user.save if @user.send_welcome_email UserMailer.welcome_email(@user).deliver end redirect_to(admin_users_url, :notice => "User #{@user.name} was successfully created.") else render :action => "new" end end In my view (haml) I am trying to access it like this: %p Send Welcome Email? = f.check_box :send_welcome_email I tried to make this an attr_accessible: :send_welcome_email but the controller does not recognize it. I get an undefined method 'send_welcome_email' for #&lt;User:0x00000100d080a8&gt; I would like it to look like this: What is the best way to get this working:

    Read the article

  • Wordpress post query php custom field conditional

    - by Andy
    Here's the situation: In wordpress I'm trying to reset a post WP_Query so that I can rewrite the post link based on whether or not a custom field exists in the post. I'm trying to give the post a NEW link in the custom field. All I've managed to do here is kill the link entirely. Any and all help is greatly appreciated, I'm pretty green to php. Here's my WP_Query: <?php $recentPosts = new WP_Query(); $recentPosts->query('showposts=3'); ?> <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?> <div <?php post_class() ?> id="post-<?php the_ID(); ?>"> <?php $attribute = the_title_attribute(); $title = the_title(); $key = 'NewPostLink'; $newLink = get_post_meta( $post->ID, $key, TRUE ); if ($newLink != '') { $theLink = get_permalink ($post->ID ); if (has_post_thumbnail()) { $image = get_the_post_thumbnail( $post->ID ); echo '<div class="thumbnailbox"><div class="thumbnail"><a href="'.$theLink.'">'.$image.'</a></div></div>'; echo '<h2><a href="'.$theLink.'" rel="bookmark" title="Permanent Link to '.$attribute.'">'.$title.'</a></h2>'; } else { echo '<h2><a href="'.$theLink.'" rel="bookmark" title="Permanent Link to '.$attribute.'">'.$title.'</a></h2>'; } } else { $theLink = $newLink; if (has_post_thumbnail()) { $image = get_the_post_thumbnail( $post->ID ); echo '<div class="thumbnailbox"><div class="thumbnail"><a href="'.$theLink.'">'.$image.'</a></div></div>'; echo '<h2><a href="'.$theLink.'" rel="bookmark" title="Permanent Link to '.$attribute.'">'.$title.'</a></h2>'; } else { echo '<h2><a href="'.$theLink.'" rel="bookmark" title="Permanent Link to '.$attribute.'">'.$title.'</a></h2>'; } } ?> <small><?php the_time('F jS, Y') ?></small> <div class="entry"> <?php the_excerpt(); ?> </div> </div> <?php endwhile; ?>

    Read the article

  • Regular Expressions - Match all alphanumeric characters except individual numbers

    - by imaginonic
    I would like to create a RegEx to match only english alphanumeric characters but ignore (or discard) isolated numbers in Ruby (and if possible in JS too). Examples: 1) I would like the following to be matched: 4chan 9gag test91323432 asf5asdfaf35edfdfad afafaffe But not: 92342424 343424 34432 and so on.. The above is exactly what I would want. 2) However, I would be really thankful if someone could also include French letters like: é ë ê (These are just few examples of many) 1) is my priority, it's totally okay if 2) is impossible or difficult to implement. Sorry, my regex skills aren't that great (hence this question!) Thank you.

    Read the article

  • Regular Expressions .NET

    - by Fosa
    I need a regular expression for some arguments that must match on a string. here it is... The string exists out of minimum 8 en maximum 20 characters. These characters of this string may be characters of the alfabet or special chars --With other words..all charachters except from the whitespaces In the complete string there must be atleast 1 number. The string cannot start with a number or an underscore The last 2 characters of the string must be identical, But it doenst matter if those last --identical characters are capital or non-capital (case insensitive) Must match all : +234567899 a_1de*Gg xy1Me*__ !41deF_hij2lMnopq3ss C234567890123$^67800 *5555555 sDF564zer"" !!!!!!!!!4!!!!!!!!!! abcdefghijklmnopq9ss May not match : Cannot be less then 8 or more then 20 chars: a_1+Eff B41def_hIJ2lmnopq3stt Cannot contain a whitespace: A_4 e*gg b41def_Hij2l nopq3ss Cannot start with a number or an underscore: __1+Eff 841DEf_hij2lmnopq3stt cannot end on 2 diffrent characters: a_1+eFg b41DEf_hij2lmnopq3st Cannot be without a number in the string: abCDefghijklmnopqrss abcdef+++dF !!!!!!!!!!!!!!!!!!!! ------------------------------------------------------ This is what I have so far...But I'm really breaking my head on this... If you Don't know the answer completely it's not a problem... I just want to get in the right direction ([^0-9_])(?=.*\d)(\S{8,20})(?i:[\S])\1

    Read the article

  • Conditional Update stored proc is firing a trigger always

    - by schar
    I have a stored procedure that says update table1 set value1 = 1 where value1 = 0 and date < getdate() I have a trigger that goes like CREATE TRIGGER NAME ON TABLENAME FOR UPDATE ... if UPDATE(value1) BEGIN --Some code to figure out that this trigger has been called -- the value is always null END Any idea why this trigger is called even when the stored procedure does not update any values?

    Read the article

< Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >