blitz-research/monkey2

Unexpected behaviour with stack.Sort(fn) and the "-" Operator ?

Closed this issue · 2 comments

I used to use the "-" operator to compare into std.collection.Stack.Sort() Lambdas but I met some unexpected sorting and will now use the "<=>" operator. But is this normal?

The following code prints a wrongly sorted stack followed by a correctly sorted stack made with a sort resp. using the - operator followed by the <=> operator.

#Import "<std>"
Using std..

Function Main()
	
	Local st:=New Stack<Double>
	st.Add(359.441293598843)
	st.Add(330.80808897393865)
	st.Add(359.2445636070442)
	st.Sort(Lambda:Int(a:Double,b:Double) 
					Return	a - b
				End ) 'doesn't work with a-b
	For Local v:=Eachin st
		Print v
	Next
	Print "---"
	st.Sort(Lambda:Int(a:Double,b:Float) 
					Return	a <=> b
				End ) 'works with a<=>b
	For Local d:=Eachin st
		Print d
	Next
End