From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,NICE_REPLY_A,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 677 invoked from network); 7 Dec 2020 11:37:15 -0000 Received: from ewsd.inri.net (107.191.116.128) by inbox.vuxu.org with ESMTPUTF8; 7 Dec 2020 11:37:15 -0000 Received: from mail-wm1-f44.google.com ([209.85.128.44]) by ewsd; Mon Dec 7 06:34:15 -0500 2020 Received: by mail-wm1-f44.google.com with SMTP id y23so1748630wmi.1 for <9front@9front.org>; Mon, 07 Dec 2020 03:34:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=OmomvtKhY/cGoiVgXer/h2tEB3In0yrIkmb6vFlR/7Y=; b=lViu5YYdKPrmhkZ9Id9GN3MdFOvqPIW0EqQkPy59HqRXqIMOquqLmSmAN4bemfm1lV 937rT9CZhAzjS2J39H91qgURDEvO1i+2nbD+8Lvgubr/h5TDG8Q5WWaW/N2JNDw8Cdtu W6sQB8cHL7RAcM0D0h6u/CjFpLWaMB9YPvvfblayEVjWe0IGA4RjnX9a/Bsb6BzFOvKT 9kAmJ4D2EZLB5FJP7kLN1SNtTLfbGg9XNEUZZCNQBACjfAOfTFsPvnC71V8oZ4qn3U9J TYsnub+J5Z74TMn09D3nk/S0QjNhuGHoX88hUmQzkhjHlGhFH/XE3aagenr8FC+5keg7 ZcLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=OmomvtKhY/cGoiVgXer/h2tEB3In0yrIkmb6vFlR/7Y=; b=ite5xD/khCkChDLBlzoTmpyEare9OjeVnV+g2AmqFhZKYklFV+li7dsbfOZ+JN91Z9 QcOJ7iHcW4wc/LPaWpuvyDSW0y9kn1OYxqc21eM9/mYuBxJNRkdm4BR/2akuV/4zayOK Jz5vjKyS0Ue6I8f2CSdPO+mazvUTHtFvZc4e2sAvjbgYOQbZlZF8D7MmLOOx6Ol27Xra 4gptqwQX4Ewixd1apKg9E62dzO4v0LxLV+Tg9f/idBf/wZvlcqb0EN9G+ZrtsWx+XcEs dPqh6TH4iHX14FGnKHlK5c0XPcXuYw6UDu2VCrQSxaRwOve3Et9lykrFK/pL2wHfgiHP Cdig== X-Gm-Message-State: AOAM533qwccuPWzyiQ3mbcKmU4SZoK435qJRRj3TtGiMigm6/7xrjJcD 1c+q9WrtOn2kW2sBMYrJn9yTk8pE6Vj+/g== X-Google-Smtp-Source: ABdhPJyjBBaZVJct0L6Xn9+pbbgGi8xP3p+QUTnMFCrH7/R06H9Isua84wSXAvn/IBxNUvoWQmwvgA== X-Received: by 2002:a7b:c843:: with SMTP id c3mr17912737wml.100.1607340849209; Mon, 07 Dec 2020 03:34:09 -0800 (PST) Return-Path: Received: from [192.168.0.19] (250.12.13.109.rev.sfr.net. [109.13.12.250]) by smtp.gmail.com with ESMTPSA id q25sm16577949wmq.37.2020.12.07.03.34.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Dec 2020 03:34:08 -0800 (PST) From: =?UTF-8?Q?Iruat=c3=a3_Souza?= To: ori@eigenstate.org, 9front@9front.org References: <23D0CE12F0A6885C041A6F186B0B2920@eigenstate.org> Message-ID: Date: Mon, 7 Dec 2020 12:34:08 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: map/reduce XML scripting-aware wrapper Subject: Re: [9front] [patch] add log2 to ape Reply-To: 9front@9front.org Precedence: bulk On 07/12/2020 11:16, Iruatã Souza wrote: > On 06/12/2020 19:49, ori@eigenstate.org wrote: >> In error cases, this divides the error return >> by log2. I suspect we don't want to do that. >> >> I'd also rather name all of the constants >> consistently. Maybe uppercase the initial >> character, instead of giving one of them >> an _ prefix. > > The patch is simply wrong, it doesn't even compile correctly! > > Sorry for the noise, here is a better one. > Now changing ape/math.h for all architectures. diff -r 3497ab777d56 386/include/ape/math.h --- a/386/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100 +++ b/386/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100 @@ -26,6 +26,7 @@ extern double ldexp(double, int); extern double log(double); extern double log10(double); +extern double log2(double); extern double modf(double, double *); extern double pow(double, double); extern double sqrt(double); diff -r 3497ab777d56 68020/include/ape/math.h --- a/68020/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100 +++ b/68020/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100 @@ -26,6 +26,7 @@ extern double ldexp(double, int); extern double log(double); extern double log10(double); +extern double log2(double); extern double modf(double, double *); extern double pow(double, double); extern double sqrt(double); diff -r 3497ab777d56 amd64/include/ape/math.h --- a/amd64/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100 +++ b/amd64/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100 @@ -26,6 +26,7 @@ extern double ldexp(double, int); extern double log(double); extern double log10(double); +extern double log2(double); extern double modf(double, double *); extern double pow(double, double); extern double sqrt(double); diff -r 3497ab777d56 arm/include/ape/math.h --- a/arm/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100 +++ b/arm/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100 @@ -26,6 +26,7 @@ extern double ldexp(double, int); extern double log(double); extern double log10(double); +extern double log2(double); extern double modf(double, double *); extern double pow(double, double); extern double sqrt(double); diff -r 3497ab777d56 arm64/include/ape/math.h --- a/arm64/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100 +++ b/arm64/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100 @@ -26,6 +26,7 @@ extern double ldexp(double, int); extern double log(double); extern double log10(double); +extern double log2(double); extern double modf(double, double *); extern double pow(double, double); extern double sqrt(double); diff -r 3497ab777d56 mips/include/ape/math.h --- a/mips/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100 +++ b/mips/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100 @@ -26,6 +26,7 @@ extern double ldexp(double, int); extern double log(double); extern double log10(double); +extern double log2(double); extern double modf(double, double *); extern double pow(double, double); extern double sqrt(double); diff -r 3497ab777d56 power/include/ape/math.h --- a/power/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100 +++ b/power/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100 @@ -26,6 +26,7 @@ extern double ldexp(double, int); extern double log(double); extern double log10(double); +extern double log2(double); extern double modf(double, double *); extern double pow(double, double); extern double sqrt(double); diff -r 3497ab777d56 sparc/include/ape/math.h --- a/sparc/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100 +++ b/sparc/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100 @@ -26,6 +26,7 @@ extern double ldexp(double, int); extern double log(double); extern double log10(double); +extern double log2(double); extern double modf(double, double *); extern double pow(double, double); extern double sqrt(double); diff -r 3497ab777d56 sparc64/include/ape/math.h --- a/sparc64/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100 +++ b/sparc64/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100 @@ -26,6 +26,7 @@ extern double ldexp(double, int); extern double log(double); extern double log10(double); +extern double log2(double); extern double modf(double, double *); extern double pow(double, double); extern double sqrt(double); diff -r 3497ab777d56 sys/src/ape/lib/ap/math/log.c --- a/sys/src/ape/lib/ap/math/log.c Mon Dec 07 00:36:41 2020 +0100 +++ b/sys/src/ape/lib/ap/math/log.c Mon Dec 07 12:29:28 2020 +0100 @@ -10,16 +10,16 @@ #include #include -#define log2 0.693147180559945309e0 -#define ln10o1 .4342944819032518276511 -#define sqrto2 0.707106781186547524e0 -#define p0 -.240139179559210510e2 -#define p1 0.309572928215376501e2 -#define p2 -.963769093377840513e1 -#define p3 0.421087371217979714e0 -#define q0 -.120069589779605255e2 -#define q1 0.194809660700889731e2 -#define q2 -.891110902798312337e1 +#define Log2 0.693147180559945309e0 +#define Ln10o1 .4342944819032518276511 +#define Sqrto2 0.707106781186547524e0 +#define P0 -.240139179559210510e2 +#define P1 0.309572928215376501e2 +#define P2 -.963769093377840513e1 +#define P3 0.421087371217979714e0 +#define Q0 -.120069589779605255e2 +#define Q1 0.194809660700889731e2 +#define Q2 -.891110902798312337e1 double log(double arg) @@ -36,7 +36,7 @@ x *= 2; exp--; } - if(x < sqrto2) { + if(x < Sqrto2) { x *= 2; exp--; } @@ -44,9 +44,9 @@ z = (x-1) / (x+1); zsq = z*z; - temp = ((p3*zsq + p2)*zsq + p1)*zsq + p0; - temp = temp/(((zsq + q2)*zsq + q1)*zsq + q0); - temp = temp*z + exp*log2; + temp = ((P3*zsq + P2)*zsq + P1)*zsq + P0; + temp = temp/(((zsq + Q2)*zsq + Q1)*zsq + Q0); + temp = temp*z + exp*Log2; return temp; } @@ -58,5 +58,16 @@ errno = (arg==0)? ERANGE : EDOM; return -HUGE_VAL; } - return log(arg) * ln10o1; + return log(arg) * Ln10o1; } + +double +log2(double arg) +{ + if(arg <= 0) { + errno = (arg==0)? ERANGE : EDOM; + return -HUGE_VAL; + } + + return log(arg)/Log2; +}