Search Results

Search found 251 results on 11 pages for 'equality'.

Page 1/11 | 1 2 3 4 5 6 7 8 9 10 11  | Next Page >

  • short-cutting equality checking in F#?

    - by John Clements
    In F#, the equality operator (=) is generally extensional, rather than intensional. That's great! Unfortunately, it appears to me that F# does not use pointer equality to short-cut these extensional comparisons. For instance, this code: type Z = MT | NMT of Z ref // create a Z: let a = ref MT // make it point to itself: a := NMT a // check to see whether it's equal to itself: printf "a = a: %A\n" (a = a) ... gives me a big fat segmentation fault[*], despite the fact that 'a' and 'a' both evaluate to the same reference. That's not so great. Other functional languages (e.g. PLT Scheme) get this right, using pointer comparisons conservatively, to return 'true' when it can be determined using a pointer comparison. So: I'll accept the fact that F#'s equality operator doesn't use short-cutting; is there some way to perform an intensional (pointer-based) equality check? The (==) operator is not defined on my types, and I'd love it if someone could tell me that it's available somehow. Or tell me that I'm wrong in my analysis of the situation: I'd love that, too... [*] That would probably be a stack overflow on Windows; there are things about Mono that I'm not that fond of...

    Read the article

  • floating point equality in Python and in general

    - by eric.frederich
    I have a piece of code that behaves differently depending on whether I go through a dictionary to get conversion factors or whether I use them directly. The following piece of code will print 1.0 == 1.0 -> False But if you replace factors[units_from] with 10.0 and factors[units_to ] with 1.0 / 2.54 it will print 1.0 == 1.0 -> True #!/usr/bin/env python base = 'cm' factors = { 'cm' : 1.0, 'mm' : 10.0, 'm' : 0.01, 'km' : 1.0e-5, 'in' : 1.0 / 2.54, 'ft' : 1.0 / 2.54 / 12.0, 'yd' : 1.0 / 2.54 / 12.0 / 3.0, 'mile' : 1.0 / 2.54 / 12.0 / 5280, 'lightyear' : 1.0 / 2.54 / 12.0 / 5280 / 5.87849981e12, } # convert 25.4 mm to inches val = 25.4 units_from = 'mm' units_to = 'in' base_value = val / factors[units_from] ret = base_value * factors[units_to ] print ret, '==', 1.0, '->', ret == 1.0 Let me first say that I am pretty sure what is going on here. I have seen it before in C, just never in Python but since Python in implemented in C we're seeing it. I know that floating point numbers will change values going from a CPU register to cache and back. I know that comparing what should be two equal variables will return false if one of them was paged out while the other stayed resident in a register. Questions What is the best way to avoid problems like this?... In Python or in general. Am I doing something completely wrong? Side Note This is obviously part of a stripped down example but what I'm trying to do is come with with classes of length, volume, etc that can compare against other objects of the same class but with different units. Rhetorical Questions If this is a potentially dangerous problem since it makes programs behave in an undetermanistic matter, should compilers warn or error when they detect that you're checking equality of floats Should compilers support an option to replace all float equality checks with a 'close enough' function? Do compilers already do this and I just can't find the information.

    Read the article

  • Get to Know a Candidate (15 of 25): Jerry White–Socialist Equality Party

    - by Brian Lanham
    DISCLAIMER: This is not a post about “Romney” or “Obama”. This is not a post for whom I am voting. Information sourced for Wikipedia. White (born Jerome White) is an American politician and journalist, reporting for the World Socialist Web Site.  White's Presidential campaign keeps four core components: * International unity in the working class * Social equality * Opposition to imperialist militarism and assault on democratic rights * Opposition to the political subordination of the working class to the Democrats and Republicans The White-Scherrer ticket is currently undergoing a review by the Wisconsin election committee concerning the ballot listing of the party for the 2012 Presidential elections. White has visited Canada, Germany, and Sri Lanka to campaign for socialism and an international working class movement. The Socialist Equality Party (SEP) is a Trotskyist political party in the United States, one of several Socialist Equality Parties around the world affiliated to the International Committee of the Fourth International (ICFI). The ICFI publishes daily news articles, perspectives and commentaries on the World Socialist Web Site. The party held public conferences in 2009 and 2010. It led an inquiry into utility shutoffs in Detroit, Michigan earlier in 2010, after which it launched a Committee Against Utility Shutoffs. Recently it sent reporters to West Virginia to report on the Upper Big Branch Mine disaster and the way that Massey Energy has treated its workers. It also sent reporters to the Gulf Coast to report on the Deepwater Horizon oil spill. In addition, it has participated in elections with the aim of opposing the American occupation of Iraq and building a mass socialist party with an international perspective. Despite having been active for over a decade, the Socialist Equality Party held its founding congress in 2008, where it adopted a statement of principles and a historical document. White has Ballot Access in: CO, LA, WI Learn more about Jerry White and Socialist Equality Party on Wikipedia

    Read the article

  • Should Equality be commutative within a Class Hierachy?

    - by vossad01
    It is easy to define the Equals operation in ways that are not commutative. When providing equality against other types, there are obviously situations (in most languages) were equality not being commutative is unavoidable. However, within one's own inheritance hierarchy where the root base class defines an equality member, a programmer has more control. Thus you can create situations where (A = B) ? (B = A), where A and B both derive from base class T Substituting the = with the appropriate variation for a given language. (.Equals(_), ==, etc.) That seems wrong to me, however, I recognize I may be biased by background in Mathematics. I have not been in programming long enough to know what is standard/accepted/preferred practice when programming. Do most programmers just accept .Equals(_)may not be commutative and code defensibly. Do they expect commutativity and get annoyed if it is not. In short, when working in a class hierarchy, should effort me made to ensure Equality is commutative?

    Read the article

  • Logical equality in C

    - by andrew cooke
    [It seems odd this doesn't exist, so apologies in advance if it's a duplicate] I want to test for logical equality in C. In other words, I want to know whether two values would be equal if both were converted in the normal way associated with logical expressions. In C99, I think that (bool)a == (bool)b gives what I want. Is that correct? What is the normal way of writing this in traditional C?

    Read the article

  • Comparing two collections for equality

    - by Crossbrowser
    I would like to compare two collections (in C#), but I'm not sure of the best way to implement this efficiently. I've read the other thread about Enumerable.SequenceEqual, but it's not exactly what I'm looking for. In my case, two collections would be equal if they both contain the same items (no matter the order). Example: collection1 = {1, 2, 3, 4}; collection2 = {2, 4, 1, 3}; collection1 == collection2; // true What I usually do is to loop through each item of one collection and see if it exists in the other collection, then loop through each item of the other collection and see if it exists in the first collection. (I start by comparing the lengths). if (collection1.Count != collection2.Count) return false; // the collections are not equal foreach (Item item in collection1) { if (!collection2.Contains(item)) return false; // the collections are not equal } foreach (Item item in collection2) { if (!collection1.Contains(item)) return false; // the collections are not equal } return true; // the collections are equal However, this is not entirely correct, and it's probably not the most efficient way to do compare two collections for equality. An example I can think of that would be wrong is: collection1 = {1, 2, 3, 3, 4} collection2 = {1, 2, 2, 3, 4} Which would be equal with my implementation. Should I just count the number of times each item is found and make sure the counts are equal in both collections? The examples are in some sort of C# (let's call it pseudo-C#), but give your answer in whatever language you wish, it does not matter. Note: I used integers in the examples for simplicity, but I want to be able to use reference-type objects too (they do not behave correctly as keys because only the reference of the object is compared, not the content).

    Read the article

  • Object equality in context of hibernate / webapp

    - by bert
    How do you handle object equality for java objects managed by hibernate? In the 'hibernate in action' book they say that one should favor business keys over surrogate keys. Most of the time, i do not have a business key. Think of addresses mapped to a person. The addresses are keeped in a Set and displayed in a Wicket RefreshingView (with a ReuseIfEquals strategy). I could either use the surrogate id or use all fields in the equals() and hashCode() functions. The problem is that those fields change during the lifetime ob the object. Either because the user entered some data or the id changes due to JPA merge() being called inside the OSIV (Open Session in View) filter. My understanding of the equals() and hashCode() contract is that those should not change during the lifetime of an object. What i have tried so far: equals() based on hashCode() which uses the database id (or super.hashCode() if id is null). Problem: new addresses start with an null id but get an id when attached to a person and this person gets merged() (re-attached) in the osiv-filter. lazy compute the hashcode when hashCode() is first called and make that hashcode @Transitional. Does not work, as merge() returns a new object and the hashcode does not get copied over. What i would need is an ID that gets assigned during object creation I think. What would be my options here? I don't want to introduce some additional persistent property. Is there a way to explicitly tell JPA to assign an ID to an object? Regards

    Read the article

  • Equality between two enumerables

    - by Berryl
    I have two enumerables with the exact same reference elements, and wondering why Equals wouldn't be true. As a side question, the code below to compare each element works, but there must be a more elegant way Cheers, Berryl var other = (ActivityService) obj; if (!AllAccounts.Count().Equals(other.AllAccounts.Count())) return false; for (int i = 0; i < AllAccounts.Count(); i++) { if (!AllAccounts.ElementAt(i).Equals(other.AllAccounts.ElementAt(i))) { return false; } } return true;

    Read the article

  • Compare equality of char[] in C

    - by rksprst
    I have two variables: char charTime[] = "TIME"; char buf[] = "SOMETHINGELSE"; I want to check if these two are equal... using charTime == buf doesn't work. What should I use, and can someone explain why using == doesn't work? Would this action be different in C and C++?

    Read the article

  • Equality with Double.NaN

    - by chris
    I have the following code... if (Price_Foreign != Double.NaN) { output.Append(spacer); output.Append(String.Format("{0,-10:C} USD",Price_Foreign)); } Which outputs: NaN USD What gives? I'm using Double.NaN to indicate that the value doesn't exist, and shouldn't be output.

    Read the article

  • What is the algorithm used by the memberwise equality test in .NET structs?

    - by Damian Powell
    What is the algorithm used by the memberwise equality test in .NET structs? I would like to know this so that I can use it as the basis for my own algorithm. I am trying to write a recursive memberwise equality test for arbitrary objects (in C#) for testing the logical equality of DTOs. This is considerably easier if the DTOs are structs (since ValueType.Equals does mostly the right thing) but that is not always appropriate. I would also like to override comparison of any IEnumerable objects (but not strings!) so that their contents are compared rather than their properties. This has proven to be harder than I would expect. Any hints will be greatly appreciated. I'll accept the answer that proves most useful or supplies a link to the most useful information. Thanks.

    Read the article

  • Double equals (Not equality) during assigning Java

    - by FabianCook
    When I tried searching this I would just get things on equality. When I was reading through some documentation for navigation in Android I had come across something I had never seen before. I came across this: mTitle = mDrawerTitle = getTitle(); It almost looks like something you can do in JavaScript where you can take the first not-null variable and assign it to a variable. In JavaScript I would do this: mTitle = mDrawerTitle || getTitle(); And it would return the first not null, in Java, is this double equals usage the equivalent in Java? What is this type of expression called?

    Read the article

  • Interesting AS3 hash situation. Is it really using strict equality as the documentation says?

    - by Triynko
    AS3 Code: import flash.utils.Dictionary; var num1:Number = Number.NaN; var num2:Number = Math.sqrt(-1); var dic:Dictionary = new Dictionary( true ); trace(num1); //NaN trace(num2); //NaN dic[num1] = "A"; trace( num1 == num2 ); //false trace( num1 === num2 ); //false trace( dic[num1] ); //A trace( dic[num2] ); //A Concerning the key comparison method... "The Dictionary class lets you create a dynamic collection of properties, which uses strict equality (===) for key comparison. When an object is used as a key, the object's identity is used to look up the object, and not the value returned from calling toString() on it." If Dictionary uses strict equality, as the documentation states, then how is it that num1 === num2 is false, and yet dic[num1] resolves to the same hash slot as dic[num2]?

    Read the article

  • is (StringComparison.)Ordinal the same as InvariantCulture for testing equality?

    - by Tim Lovell-Smith
    From what I read so far, it sounds like these StringComparison types are meant to differ in how they do sorting of strings, if so, does that mean that it does'nt matter which StringComparison you use when doing an equality comparison? string.Equals(a, b, StringComparison....) Extra credit: does it make a difference to the answer if we compare OrdinalIgnoreCase and InvariantCultureIgnoreCase? What is the answer then? Please provide supporting argument and/or references.

    Read the article

  • C# string equality operator returns false, but I'm pretty sure it should be true... What?!

    - by Daniel Schaffer
    I'm trying to write a unit test for a piece of code that generates a large amount of text. I've run into an issue where the "expected" and "actual" strings appear to be equal, but Assert.AreEqual throws, and both the equality operator and Equals() return false. The result of GetHashCode() is different for both values as well. However, putting both strings into text files and comparing with DiffMerge tells me they're the same. Additionally, using Encoding.ASCII.GetBytes() on both values and then using SequenceEquals to compare the resulting byte arrays returns true. The values are 34KB each, so I'll hold off putting them here for now. Any ideas? I'm completely stumped.

    Read the article

  • Undocumented Query Plans: Equality Comparisons

    - by Paul White
    The diagram below shows two data sets, with differences highlighted: To find changed rows using TSQL, we might write a query like this: The logic is clear: join rows from the two sets together on the primary key column, and return rows where a change has occurred in one or more data columns.  Unfortunately, this query only finds one of the expected four rows: The problem, of course, is that our query does not correctly handle NULLs.  The ‘not equal to’ operators <> and != do not evaluate...(read more)

    Read the article

  • Partitioning set into subsets with respect to equality of sum among subsets

    - by Al.Net
    let say i have {3, 1, 1, 2, 2, 1,5,2,7} set of numbers, I need to split the numbers such that sum of subset1 should be equal to sum of subset2 {3,2,7} {1,1,2,1,5,2}. First we should identify whether we can split number(one way might be dividable by 2 without any remainder) and if we can, we should write our algorithm two create s1 and s2 out of s. How to proceed with this approach? I read partition problem in wiki and even in some articles but i am not able to get anything. Can someone help me to find the right algorithm and its explanation in simple English?

    Read the article

  • Equality and Assigment Operators

    - by Jeremy Smith
    I have a assembly compiled in VB.NET that contains two operators: Public Shared Operator =(quarterA As CalendarQuarter, quarterB As CalendarQuarter) As Boolean Return quarterA.StartDate = quarterB.StartDate AndAlso quarterA.EndDate = quarterB.EndDate AndAlso quarterA.Quarter = quarterB.Quarter End Operator Public Shared Operator <>(quarterA As CalendarQuarter, quarterB As CalendarQuarter) As Boolean Return Not (quarterA = quarterB) End Operator However, when using the assembly in C# to perform equality checks if (qtr != null) I receive the error: Cannot implicity convert type 'object' to 'bool' My original intent with the = operator was only for assignment purposes in VB, so I may be way off base (I don't use custom operators too often). What do I need to do to make the operator behave with both equality and assignment operations?

    Read the article

  • Hibernate object equality checking

    - by Sujee
    As far as I understand(correct me if I am wrong) Hibernate uses object reference to check the object equality. When Hibernate identifies that there are more than one objects attached to same DB record, it throws following exception. "a different object with the same identifier value was already associated with the session" My question is, does Hibernate use equal() method to check the object equality (The default equal method uses object reference)? If it is true, will overridden equal() method change the Hibernate behavior? Note: My question is not about the issues of implementing equal() or hashCode() methods in a Hibernate persisted object. Thank you.

    Read the article

  • Why does `Array(0,1,2) == Array(0,1,2)` not return the expected result?

    - by soc
    As far as I understand, Scala's == defines the natural equality of two objects. I expected that Array(0,1,2) == Array(0,1,2) compares the natural equality e. g. checks if all elements of the array return true when compared with the corresponding elements of the other array. People told me that Scala's Array is just a Java [] which only compares identity. But Scala's String is also just a Java String but Scala overrides equals to compare natural equality. I wonder why Array's equals method was not overridden, too. Thank you for your thoughts!

    Read the article

  • When would JavaScript == make more sense than ===?

    - by bryantsai
    As 359494 indicates they are basically identical except '===' also ensures type equality and hence '==' might perform type conversion. In Douglas Crockford's JavaScript: The Good Parts, it is advised to always avoid '=='. However, I'm wondering what the original thought of designing two set of equality operators was. Have you seen any situation that using '==' actually is more suitable than using '==='?

    Read the article

  • prolog program to find equality of two lists in any order

    - by Happy Mittal
    I wanted to write a prolog program to find equality of two lists, the order of elements doesn't matter. So I wrote following: del( _ , [ ] , [ ] ) . del( X , [ X|T ] , T ). del( X , [ H|T ] , [ H|T1 ] ) :- X \= H , del( X , T , T1 ). member( X, [ X | _ ] ) . member( X, [ _ | T ] ) :- member( X, T ). equal( [ ], [ ] ). equal( [X], [X] ). equal( [H1|T], L2 ) :- member( H1, L2 ), del( H1, L2, L3), equal(T , L3 ). But when I give input like equal([1,2,3],X)., it doesn't show all possible values of X. instead the program hangs in the middle. What could be the reason?

    Read the article

  • double.NaN Equality in MS Test

    - by RichK
    Why am I getting this result? [TestMethod] public void nan_test() { Assert.AreEqual(1, double.NaN, 1E-1); <-- Passes Assert.AreEqual(1, double.NaN); <-- Fails } What difference does the delta have in asserting NaN equals a number? Surely it should always return false. I am aware of IsNaN, but that's not useful here (see below). Background: I have a function returning NaN (erroneously) , it was meant to be a real number but the test still passed. I'm using the delta because it's double precision equality, the original test used 1E-9.

    Read the article

1 2 3 4 5 6 7 8 9 10 11  | Next Page >