Skip to content

[fork-ffi] numbers: min — Same defect as max #98

@Unisay

Description

@Unisay

Package: purescript-lua-numbers
File: src/Data/Number.lua
Function: min
Class: semantics Severity: medium

Same defect as max. PureScript docstring (Number.purs lines 200-202) requires NaN if either argument is NaN. Lua math.min folds with <, and nan < x is false, so min(1)(nan) returns 1 (confirmed under Lua 5.1) instead of NaN; NaN propagation is order-dependent.

Current (Lua):

min = (function(n1) return function(n2) return math.min(n1, n2) end end)

Expected: min NaN x = NaN and min x NaN = NaN for any x, like JS Math.min.

Proposed fix:

Add an explicit NaN guard: `function(n1) return function(n2) if n1 ~= n1 or n2 ~= n2 then return 0/0 else return math.min(n1, n2) end end end`.

Found by the FFI audit; reproduced under Lua 5.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions