History

Issue 122: Allow floating point return values from Array.sort callback.

Tor Andersson committed 6 years ago

Commit e690d311 parent b4484ab1 file · +3 −1Browse files

Showing the changes to jsarray.c (1 of 1 file). Show all

Unified · Split

jsarray.c+3−1
@@ -259,6 +259,7 @@ static int sortcmp(const void *avoid, const void *bvoid) · 258 unmodified lines
259259 const js_Value *a = &aslot->v, *b = &bslot->v;
260260 js_State *J = aslot->J;
261261 const char *sx, *sy;
262+ double v;
262263 int c;
263264
264265 int unx = (a->type == JS_TUNDEFINED);
@@ -272,7 +273,8 @@ static int sortcmp(const void *avoid, const void *bvoid) · 7 unmodified lines
272273 js_pushvalue(J, *a);
273274 js_pushvalue(J, *b);
274275 js_call(J, 2);
275− c = js_tonumber(J, -1);
276+ v = js_tonumber(J, -1);
277+ c = (v == 0) ? 0 : (v < 0) ? -1 : 1;
276278 js_pop(J, 1);
277279 } else {
278280 js_pushvalue(J, *a);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t