lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, Jan 18, 2013 at 9:58 AM, martinwguy <martinwguy@gmail.com> wrote:
> On 18 January 2013 14:38, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>> There's no math.asinh, math.acosh, math.atanh.
>>
>> The reason presumably being that ANSI C does not provide
>> them.
>>
>> But if your C compiler provides it, you may find the included
>> file useful.
>
> Or
> math.asinh = function (x) return math.log(x + math.sqrt(x * x + 1)); end
> math.acosh = function (x) return math.log(x + math.sqrt(x * x - 1)); end
> math.atanh = function(x) return (math.log(1 + x) - math.log(1 - x)) / 2; end
>
>    M
>

Better yet,

do
    local sqrt = math.sqrt
    local log = math.log
    math.asinh = function(x) return log(x + sqrt(x*x + 1)) end
    math.acosh = function(x) return log(x + sqrt(x*x - 1)) end
    math.atanh = function(x) return (log(1 + x) - log(1 - x)) / 2 end
end

Because you've got to squeeze out those cycles donchaknow.

/s/ Adam