Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

We are MicroSoft. You will be assimilated. Resistance is futile. (Attributed to B.G., Gill Bates)


devel / comp.lang.c++ / Re: How can I get an implementation of fmod()?

SubjectAuthor
* How can I get an implementation of fmod()?Megumin
+* Re: How can I get an implementation of fmod()?Bonita Montero
|`- Re: How can I get an implementation of fmod()?Bonita Montero
+- Re: How can I get an implementation of fmod()?Bonita Montero
`* Re: How can I get an implementation of fmod()?James Kuyper
 +* Re: How can I get an implementation of fmod()?Bonita Montero
 |`* Re: How can I get an implementation of fmod()?Bonita Montero
 | `* Re: How can I get an implementation of fmod()?Bonita Montero
 |  `* Re: How can I get an implementation of fmod()?Megumin
 |   +- Re: How can I get an implementation of fmod()?Bonita Montero
 |   +- Re: How can I get an implementation of fmod()?Ben Bacarisse
 |   `- Re: How can I get an implementation of fmod()?Keith Thompson
 `- Re: How can I get an implementation of fmod()?James Kuyper

1
How can I get an implementation of fmod()?

<b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1184&group=comp.lang.c%2B%2B#1184

  copy link   Newsgroups: comp.lang.c++
X-Received: by 2002:a05:622a:14e:b0:403:a627:8b79 with SMTP id v14-20020a05622a014e00b00403a6278b79mr348419qtw.13.1692944735936;
Thu, 24 Aug 2023 23:25:35 -0700 (PDT)
X-Received: by 2002:a05:622a:1b8e:b0:410:7d71:cef2 with SMTP id
bp14-20020a05622a1b8e00b004107d71cef2mr305464qtb.3.1692944735777; Thu, 24 Aug
2023 23:25:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c++
Date: Thu, 24 Aug 2023 23:25:35 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=173.82.121.211; posting-account=ExaCjAoAAACet7v0qEPmX8X-WEeV2WxS
NNTP-Posting-Host: 173.82.121.211
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
Subject: How can I get an implementation of fmod()?
From: chrisramirez0227@gmail.com (Megumin)
Injection-Date: Fri, 25 Aug 2023 06:25:35 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Megumin - Fri, 25 Aug 2023 06:25 UTC

How does remainder() in cmath works and is there any simple but fairly precise fmod that can be implemented without using double or long double?
I'm currently trying to implement fmodf(float x,float y) myself in assembly, and seems like in IEEE754, if I try to do as follows, the precision will f-up badly if x>>y in fact if x/y is more than 2^23 this will just makes no sense at all.
r1 = f32(x);
r2 = f32(y);
r3 = div_f32(r1,r2); //precision:2ulp
r4 = trunc(r3)// this is where things go bad if r3 is more than 2^23 it does nothing and I will get no remainder.
r4 = multi_f32(r4,r2);
r4 = subtract_f32(r1,r4);
result = r4;

Re: How can I get an implementation of fmod()?

<uc9km9$3ttlb$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1185&group=comp.lang.c%2B%2B#1185

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: How can I get an implementation of fmod()?
Date: Fri, 25 Aug 2023 09:19:40 +0200
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <uc9km9$3ttlb$1@dont-email.me>
References: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Aug 2023 07:19:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b587a1518818f1bb298ac3db843a8302";
logging-data="4126379"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18IsvguG2os7Z8GatekcqEofadvNisTbFk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:HsI0xOFVLPmQhTKMvkPaL/vC42k=
In-Reply-To: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Fri, 25 Aug 2023 07:19 UTC

Am 25.08.2023 um 08:25 schrieb Megumin:
> How does remainder() in cmath works and is there any simple but fairly precise fmod that can be implemented without using double or long double?
> I'm currently trying to implement fmodf(float x,float y) myself in assembly, and seems like in IEEE754, if I try to do as follows, the precision will f-up badly if x>>y in fact if x/y is more than 2^23 this will just makes no sense at all.
> r1 = f32(x);
> r2 = f32(y);
> r3 = div_f32(r1,r2); //precision:2ulp
> r4 = trunc(r3)// this is where things go bad if r3 is more than 2^23 it does nothing and I will get no remainder.
> r4 = multi_f32(r4,r2);
> r4 = subtract_f32(r1,r4);
> result = r4;
>

Look at the /sysdeps/ieee754/dbl-64/e_fmod.c glibc code. They've changed
the code for the 8/1/2023 release and made the algorithm multiple times
faster. The fmod() result has no precision loss.
Don't bother with x87's FPREM. It's claimed to be excact but actally its
an approximation on the CPU's I've recently checked (Zen1, Zen2, Zen4,
Skylake).

Re: How can I get an implementation of fmod()?

<uc9ljs$3u32p$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1186&group=comp.lang.c%2B%2B#1186

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: How can I get an implementation of fmod()?
Date: Fri, 25 Aug 2023 09:35:26 +0200
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <uc9ljs$3u32p$1@dont-email.me>
References: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
<uc9km9$3ttlb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 25 Aug 2023 07:35:24 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b587a1518818f1bb298ac3db843a8302";
logging-data="4131929"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/623SGaWWp7CS9mI1xC5RbhsqpkecepOM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:twzNpY3UiDCrKrZtFrGGam8P25Y=
Content-Language: de-DE
In-Reply-To: <uc9km9$3ttlb$1@dont-email.me>
 by: Bonita Montero - Fri, 25 Aug 2023 07:35 UTC

Am 25.08.2023 um 09:19 schrieb Bonita Montero:
> Am 25.08.2023 um 08:25 schrieb Megumin:
>> How does remainder() in cmath works and is there any simple but fairly
>> precise fmod that can be implemented without using double or long double?
>> I'm currently trying to implement fmodf(float x,float y) myself in
>> assembly, and seems like in IEEE754, if I try to do as follows, the
>> precision will f-up badly if x>>y in fact if x/y is more than 2^23
>> this will just makes no sense at all.
>> r1 = f32(x);
>> r2 = f32(y);
>> r3 = div_f32(r1,r2);        //precision:2ulp
>> r4 = trunc(r3)// this is where things go bad if r3 is more than 2^23
>> it does nothing and I will get no remainder.
>> r4 = multi_f32(r4,r2);
>> r4 = subtract_f32(r1,r4);
>> result = r4;
>>

The problem with your solution is that your div_f32 might loss
bits right from the mantissa but before the comma. This might
yield a result that is larger than the dividend.

> Look at the /sysdeps/ieee754/dbl-64/e_fmod.c glibc code. They've changed
> the code for the 8/1/2023 release and made the algorithm multiple times
> faster. The fmod() result has no precision loss.
> Don't bother with x87's FPREM. It's claimed to be excact but actally its
> an approximation on the CPU's I've recently checked (Zen1, Zen2, Zen4,
> Skylake).

Re: How can I get an implementation of fmod()?

<uc9me0$3u7d2$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1187&group=comp.lang.c%2B%2B#1187

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: How can I get an implementation of fmod()?
Date: Fri, 25 Aug 2023 09:49:22 +0200
Organization: A noiseless patient Spider
Lines: 101
Message-ID: <uc9me0$3u7d2$1@dont-email.me>
References: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Aug 2023 07:49:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b587a1518818f1bb298ac3db843a8302";
logging-data="4136354"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cJhqTYOmEwzYoppCpWvWiVgZfbdCiwC8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:z2ZdYVH0AAEjtiKgIZBKRRtnDuM=
Content-Language: de-DE
In-Reply-To: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
 by: Bonita Montero - Fri, 25 Aug 2023 07:49 UTC

Am 25.08.2023 um 08:25 schrieb Megumin:
> How does remainder() in cmath works and is there any simple but fairly precise fmod that can be implemented without using double or long double?
> I'm currently trying to implement fmodf(float x,float y) myself in assembly, and seems like in IEEE754, if I try to do as follows, the precision will f-up badly if x>>y in fact if x/y is more than 2^23 this will just makes no sense at all.
> r1 = f32(x);
> r2 = f32(y);
> r3 = div_f32(r1,r2); //precision:2ulp
> r4 = trunc(r3)// this is where things go bad if r3 is more than 2^23 it does nothing and I will get no remainder.
> r4 = multi_f32(r4,r2);
> r4 = subtract_f32(r1,r4);
> result = r4;
>

Here's some fmod()-code I implemented myself for float and double.
It always produces results without precision loss because the result
is always smaller than the dividend.

template<floating_point Float>
static Float myFmodT( Float counter, Float denom )
{ constexpr bool IS_DOUBLE = same_as<Float, double>;
static_assert(IS_DOUBLE || same_as<Float, float>);
constexpr unsigned
BITS = IS_DOUBLE ? 64 : 32,
MANT_BITS = IS_DOUBLE ? 52 : 23,
EXP_BITS = IS_DOUBLE ? 11 : 8;
static_assert(sizeof(Float) * 8 == BITS &&
numeric_limits<Float>::is_iec559);
using bin_t = conditional_t<IS_DOUBLE, uint64_t, uint32_t>;
constexpr int MAX_EXP = (1 << EXP_BITS) - 1;
constexpr bin_t
SIGN_BIT = (bin_t)1 << BITS - 1,
EXP_MASK = (bin_t)MAX_EXP << MANT_BITS,
IMPLCIT_BIT = (bin_t)1 << MANT_BITS,
MANT_MASK = IMPLCIT_BIT - 1;
static auto bin = []( Float f ) -> bin_t { return bit_cast<bin_t>( f ); };
static auto flt = []( bin_t b ) -> Float { return bit_cast<Float>( b ); };
bin_t
bCounter = bin( counter ),
bDenom = bin( denom ) & ~SIGN_BIT,
bSign = bCounter & SIGN_BIT;
bCounter &= ~SIGN_BIT;
static auto maxExp = []( bin_t b ) -> bool { return b >= EXP_MASK; };
static auto infMant = []( bin_t b ) -> bool { return !(b & MANT_MASK); };
auto floatingResult = [&]() -> Float { return (counter * denom) /
(counter * denom); };
if( !bDenom ) [[unlikely]]
// ... % +/-0.0
return floatingResult();
if( maxExp( bCounter ) ) [[unlikely]]
// [Inf|NaN|SNaN] % non-zero
return floatingResult();
if( maxExp( bDenom ) ) [[unlikely]]
if( infMant( bDenom ) ) [[likely]]
// finite % Inf
return counter;
else
// finite % [Inf|NaN|SNaN]
return floatingResult();
if( !bCounter ) [[unlikely]]
// +/-0.0 % non-zero-finite = +/-0.0
return counter;
int
counterExp = bCounter >> MANT_BITS & MAX_EXP,
denomExp = bDenom >> MANT_BITS & MAX_EXP;
bin_t
counterMant = (bin_t)(bool)counterExp << MANT_BITS | bCounter & MANT_MASK,
denomMant = (bin_t)(bool)denomExp << MANT_BITS | bDenom & MANT_MASK;
static auto normalize = []( bin_t &mant, int &exp )
{
unsigned bits = countl_zero( mant ) - EXP_BITS;
mant <<= bits;
exp -= bits;
};
if( !counterExp ) [[unlikely]]
// normalize counter
normalize( counterMant, counterExp ),
++counterExp;
if( !denomExp ) [[unlikely]]
// normalize denominator
normalize( denomMant, denomExp ),
++denomExp;
int remExp = counterExp;
bin_t remMant = counterMant;
for( ; ; )
{
int below = remMant < denomMant;
if( remExp - below < denomExp ) [[unlikely]]
break;
remExp -= below;
remMant <<= below;
if( !(remMant -= denomMant) ) [[unlikely]]
return flt( bSign );
normalize( remMant, remExp );
}
if( remExp <= 0 ) [[unlikely]]
// denormal result
remMant >>= -remExp + 1,
remExp = 0;
return flt( bSign | (bin_t)remExp << MANT_BITS | remMant & MANT_MASK );
}

Re: How can I get an implementation of fmod()?

<uc9p27$3ului$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1188&group=comp.lang.c%2B%2B#1188

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuyper@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c++
Subject: Re: How can I get an implementation of fmod()?
Date: Fri, 25 Aug 2023 04:34:15 -0400
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <uc9p27$3ului$1@dont-email.me>
References: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 25 Aug 2023 08:34:15 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0395eadd98ae1d5f95d4ecc4dc8b4704";
logging-data="4151250"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/pOML4OjJwC+GqkMsw5hy2PgOfVHbmDIk="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:tLd8dj5dTFsUAXTy9cIE7p5fhPk=
Content-Language: en-US
In-Reply-To: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
 by: James Kuyper - Fri, 25 Aug 2023 08:34 UTC

On 8/25/23 02:25, Megumin wrote:
> How does remainder() in cmath works ...

"The remainder functions compute the remainder x REM y required by IEC
60559. 259)" (7.12.10.2p2). Note that ISO/IEC 60559 is equivalent to
IEEE 754. That "259" refers to footnote 259, which quote that standard
as saying:

"When y ̸= 0, the remainder r = x REM y is defined regardless of the
rounding mode by the mathematical relation r = x − ny, where n is the
integer nearest the exact value of x/y; whenever |n − x| = 1/2 , then n
is even. If r = 0, its sign shall be that of x."

"The roundeven functions round their argument to the nearest integer
value in floating-point format, rounding halfway cases to even (that is,
to the nearest value that is an even integer), regardless of the current
rounding direction." (7.12.9.8p2)

Therefore, an implementation could define

float remainderf(float x, thus y) {
return x - roundevenf(x/y)*y;
}

> and is there any simple but fairly precise fmod that can be
> implemented without using double or long double?

"The fmod functions return the value x − ny, for some integer n such
that, if y is nonzero, the result has the same sign as x and magnitude
less than the magnitude of y. If y is zero, whether a domain error
occurs or the fmod functions return zero is implementation-defined."
(7.12.10.1p3).

"The trunc functions round their argument to the integer value, in
floating format, nearest to but no larger in magnitude than the
argument." (7.12.9.1p2)

Therefore, an implementation could define

float fmodf(float x,float y) {
return x - truncf(x/y)*y;
}

The "but no larger in magnitude" specification for trunc() guarantees
that this subtraction has the same sign as x, as is required for fmod().

> I'm currently trying to implement fmodf(float x,float y) myself in
> assembly, and seems like in IEEE754, if I try to do as follows, the
> precision will f-up badly if x>>y in fact if x/y is more than 2^23
> this will just makes no sense at all.

You say that you're doing it in assembly, which I couldn't help you
with, but the following looks a lot more like C than assembly.

> r1 = f32(x);
> r2 = f32(y);
> r3 = div_f32(r1,r2); //precision:2ulp
> r4 = trunc(r3)// this is where things go bad if r3 is more than 2^23
> it does nothing and I will get no remainder.
> r4 = multi_f32(r4,r2); r4 = subtract_f32(r1,r4);
> result = r4;
I suspect that it is not possible, and therefore not required by IEC
754, to produce a more accurate result than that in those cases. On the
other hand, it's 03:42 here right now, and I couldn't find my copy of
IEEE 754, so I can't be sure that I'm remembering and thinking about
that correctly.

Re: How can I get an implementation of fmod()?

<uc9p8a$3up4g$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1189&group=comp.lang.c%2B%2B#1189

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: How can I get an implementation of fmod()?
Date: Fri, 25 Aug 2023 10:37:32 +0200
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <uc9p8a$3up4g$1@dont-email.me>
References: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
<uc9p27$3ului$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Aug 2023 08:37:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b587a1518818f1bb298ac3db843a8302";
logging-data="4154512"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jmoWEdRL+u+up+AOBLxVJMNvkUjzrz+k="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:URQEFmP4csoxNYmSz5drHjPA8Xw=
Content-Language: de-DE
In-Reply-To: <uc9p27$3ului$1@dont-email.me>
 by: Bonita Montero - Fri, 25 Aug 2023 08:37 UTC

Am 25.08.2023 um 10:34 schrieb James Kuyper:

> float fmodf(float x,float y) {
> return x - truncf(x/y)*y;
> }

This doesn't work because when the exponent difference of x and y is
too large there might be integer-bits before the fraction of the div
-result lost so that the difference becomes larger than y.
A proper solution is much more complex. Check the solution I've shown
in this thread or the recend 8/1/2023 glibc solution in /sysdepes
/ieee754/dbl-64/e_fmod.c.

Re: How can I get an implementation of fmod()?

<uc9pjv$3uscl$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1190&group=comp.lang.c%2B%2B#1190

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: How can I get an implementation of fmod()?
Date: Fri, 25 Aug 2023 10:43:45 +0200
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <uc9pjv$3uscl$1@dont-email.me>
References: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
<uc9p27$3ului$1@dont-email.me> <uc9p8a$3up4g$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Aug 2023 08:43:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b587a1518818f1bb298ac3db843a8302";
logging-data="4157845"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//pGIc1gwA9KQE8ffRThVl6mWUxsHTCGg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:1DsjuZTpnAOVdYWJbA+4LQlJioI=
In-Reply-To: <uc9p8a$3up4g$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Fri, 25 Aug 2023 08:43 UTC

Am 25.08.2023 um 10:37 schrieb Bonita Montero:
> Am 25.08.2023 um 10:34 schrieb James Kuyper:
>
>> float fmodf(float x,float y) {
>> return x - truncf(x/y)*y;
>> }
>
> This doesn't work because when the exponent difference of x and y is
> too large there might be integer-bits before the fraction of the div
> -result lost so that the difference becomes larger than y.
> A proper solution is much more complex. Check the solution I've shown
> in this thread or the recend 8/1/2023 glibc solution in /sysdepes
> /ieee754/dbl-64/e_fmod.c.

Check this code:

#include <iostream>
#include <cmath>
#include <bit>
#include <cstdint>

using namespace std;

int main()
{ double
a = bit_cast<double>( (uint64_t)0x7FE << 52 ),
b = bit_cast<double>( 1.0 );
cout << b - trunc( a / b ) << endl;
}

The result should be >= 0.0 and < 1.0 and my computer prints:

-8.98847e+307

Re: How can I get an implementation of fmod()?

<uc9pma$3uqou$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1191&group=comp.lang.c%2B%2B#1191

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuyper@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c++
Subject: Re: How can I get an implementation of fmod()?
Date: Fri, 25 Aug 2023 04:44:58 -0400
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <uc9pma$3uqou$1@dont-email.me>
References: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
<uc9p27$3ului$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Aug 2023 08:44:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0395eadd98ae1d5f95d4ecc4dc8b4704";
logging-data="4156190"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jN5j8DBk76UMCbM5iH9XJJ+I1fX5VJv4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:pxgcX72hqNpNDbN6Fzmmg/tMzZE=
Content-Language: en-US
In-Reply-To: <uc9p27$3ului$1@dont-email.me>
 by: James Kuyper - Fri, 25 Aug 2023 08:44 UTC

On 8/25/23 04:34, James Kuyper wrote:
> On 8/25/23 02:25, Megumin wrote:
>> How does remainder() in cmath works ...

I just noticed that this message was posted on comp.lang.c++, whereas
the content left me with the incorrect impression that it had been
posted to comp.lang.c. All of the citations I gave were from the C
standard. That's still appropriate in comp.lang.c++, because the C++
standard doesn't say anything relevant itself about these issues, but
only cross-references the C standard - but I should have mentioned that
fact. Also, I should have specified C++ overloads of the math functions
for float arguments, rather than the corresponding C functions with 'f'
suffixes.

Re: How can I get an implementation of fmod()?

<uc9rp2$3v9fp$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1192&group=comp.lang.c%2B%2B#1192

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: How can I get an implementation of fmod()?
Date: Fri, 25 Aug 2023 11:20:36 +0200
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <uc9rp2$3v9fp$1@dont-email.me>
References: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
<uc9p27$3ului$1@dont-email.me> <uc9p8a$3up4g$1@dont-email.me>
<uc9pjv$3uscl$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Aug 2023 09:20:34 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b587a1518818f1bb298ac3db843a8302";
logging-data="4171257"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/qxOnrx+7UEjpIz7jRVF1ToA/EMNePifA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:qxNzv9N8OBfin8JJGuutsQ15QU0=
Content-Language: de-DE
In-Reply-To: <uc9pjv$3uscl$1@dont-email.me>
 by: Bonita Montero - Fri, 25 Aug 2023 09:20 UTC

The code before was bullshit.

#include <iostream>
#include <cmath>

using namespace std;

int main()
{ constexpr double
A = 0x1.FFFFFFFFFFFFFp+1023,
B = 3.14;
cout << A - trunc( A / B ) * B << endl;
}

Take this. For my computer this prints: 1.99584e+292

Re: How can I get an implementation of fmod()?

<c82f7211-7ce0-4fa9-8b45-d5571f4895cbn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1258&group=comp.lang.c%2B%2B#1258

  copy link   Newsgroups: comp.lang.c++
X-Received: by 2002:a05:620a:1a83:b0:76d:8643:58b5 with SMTP id bl3-20020a05620a1a8300b0076d864358b5mr54174qkb.13.1693461154894;
Wed, 30 Aug 2023 22:52:34 -0700 (PDT)
X-Received: by 2002:a05:6870:b1d5:b0:1c8:e107:4185 with SMTP id
x21-20020a056870b1d500b001c8e1074185mr615916oak.5.1693461154655; Wed, 30 Aug
2023 22:52:34 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c++
Date: Wed, 30 Aug 2023 22:52:34 -0700 (PDT)
In-Reply-To: <uc9rp2$3v9fp$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=173.82.121.211; posting-account=ExaCjAoAAACet7v0qEPmX8X-WEeV2WxS
NNTP-Posting-Host: 173.82.121.211
References: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
<uc9p27$3ului$1@dont-email.me> <uc9p8a$3up4g$1@dont-email.me>
<uc9pjv$3uscl$1@dont-email.me> <uc9rp2$3v9fp$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c82f7211-7ce0-4fa9-8b45-d5571f4895cbn@googlegroups.com>
Subject: Re: How can I get an implementation of fmod()?
From: chrisramirez0227@gmail.com (Megumin)
Injection-Date: Thu, 31 Aug 2023 05:52:34 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1622
 by: Megumin - Thu, 31 Aug 2023 05:52 UTC

After researching I found something that seems quite correct but I ain't implement it yet.(for this is going to be running on a hardware which can process one operation for 1024 numbers at once so using indefinite loops is not recommended)
float temp = y;
while((temp<<1)<x)temp<<=1;
while(x>y){
if(x>temp)x-=temp;
temp/=2;
} no matter what thank you all for your insights.

Re: How can I get an implementation of fmod()?

<ucpks5$364pb$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1261&group=comp.lang.c%2B%2B#1261

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: How can I get an implementation of fmod()?
Date: Thu, 31 Aug 2023 11:00:53 +0200
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <ucpks5$364pb$2@dont-email.me>
References: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
<uc9p27$3ului$1@dont-email.me> <uc9p8a$3up4g$1@dont-email.me>
<uc9pjv$3uscl$1@dont-email.me> <uc9rp2$3v9fp$1@dont-email.me>
<c82f7211-7ce0-4fa9-8b45-d5571f4895cbn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 31 Aug 2023 09:00:53 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ff70a7335e595a5f320387c3a69d8d92";
logging-data="3347243"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+3MWr+WeGAmrhL67yCghw5GrhXyUORc0M="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:SNGC0WeYCMmZVBXt+oQKAFKd/II=
Content-Language: de-DE
In-Reply-To: <c82f7211-7ce0-4fa9-8b45-d5571f4895cbn@googlegroups.com>
 by: Bonita Montero - Thu, 31 Aug 2023 09:00 UTC

Am 31.08.2023 um 07:52 schrieb Megumin:
> After researching I found something that seems quite correct but I ain't implement it yet.(for this is going to be running on a hardware which can process one operation for 1024 numbers at once so using indefinite loops is not recommended)
> float temp = y;
> while((temp<<1)<x)temp<<=1;

Trying to shift floats ?

> while(x>y){
> if(x>temp)x-=temp;
> temp/=2;
> }
> no matter what thank you all for your insights.

Re: How can I get an implementation of fmod()?

<87cyz3kkfb.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1277&group=comp.lang.c%2B%2B#1277

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c++
Subject: Re: How can I get an implementation of fmod()?
Date: Thu, 31 Aug 2023 21:48:24 +0100
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <87cyz3kkfb.fsf@bsb.me.uk>
References: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
<uc9p27$3ului$1@dont-email.me> <uc9p8a$3up4g$1@dont-email.me>
<uc9pjv$3uscl$1@dont-email.me> <uc9rp2$3v9fp$1@dont-email.me>
<c82f7211-7ce0-4fa9-8b45-d5571f4895cbn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="b4e95399c10c70c93d0dbe52083af2de";
logging-data="3618629"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/H3TiujlCOVtloCTagABUSIgZGMc05/O8="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:txxj51kpA9Lz/FBGs0IBbUB8JsA=
sha1:I0CSFjdt5tvfn+yRvGGBOFFkBfo=
X-BSB-Auth: 1.eb47a413ca7e132f1d66.20230831214824BST.87cyz3kkfb.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 31 Aug 2023 20:48 UTC

Megumin <chrisramirez0227@gmail.com> writes:

> After researching I found something that seems quite correct but I
> ain't implement it yet.

Have you tried:

x - (int)(x/y) * y

? Obviously you might be worried about corner cases and accuracy, but
that is at least a starting point.

> float temp = y;
> while((temp<<1)<x)temp<<=1;
> while(x>y){
> if(x>temp)x-=temp;
> temp/=2;
> }

This is not valid C or C++. If can point to where you found it, maybe
we can help make some sense of what it is trying to achieve?

--
Ben.

Re: How can I get an implementation of fmod()?

<87jzta99lq.fsf@nosuchdomain.example.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1278&group=comp.lang.c%2B%2B#1278

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c++
Subject: Re: How can I get an implementation of fmod()?
Date: Thu, 31 Aug 2023 14:37:37 -0700
Organization: None to speak of
Lines: 23
Message-ID: <87jzta99lq.fsf@nosuchdomain.example.com>
References: <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com>
<uc9p27$3ului$1@dont-email.me> <uc9p8a$3up4g$1@dont-email.me>
<uc9pjv$3uscl$1@dont-email.me> <uc9rp2$3v9fp$1@dont-email.me>
<c82f7211-7ce0-4fa9-8b45-d5571f4895cbn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="e8d899b8fafb490ef1d8e527231431ae";
logging-data="3631754"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18bKYPXCmYgmB/33KzRoD63"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:OA/yz7+hOG2ruShoiX5vc2367tQ=
sha1:cIiTWT9G2O0aATgrqBnn5yeton4=
 by: Keith Thompson - Thu, 31 Aug 2023 21:37 UTC

Megumin <chrisramirez0227@gmail.com> writes:
> After researching I found something that seems quite correct but I
> ain't implement it yet.(for this is going to be running on a hardware
> which can process one operation for 1024 numbers at once so using
> indefinite loops is not recommended)
> float temp = y;
> while((temp<<1)<x)temp<<=1;
> while(x>y){
> if(x>temp)x-=temp;
> temp/=2;
> }
> no matter what thank you all for your insights.

Suggestion: Always compile code before posting it.

The "<<" operator cannot be applied to floating-point operands.

And indentation makes code much more legible.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor