Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Kiss your keyboard goodbye!


devel / comp.lang.c / Re: eficient float sign routine

SubjectAuthor
* eficient float sign routinefir
+* Re: eficient float sign routineBen
|+* Re: eficient float sign routinefir
||`* Re: eficient float sign routinefir
|| `* Re: eficient float sign routinefir
||  +- Re: eficient float sign routinefir
||  `* Re: eficient float sign routineBen
||   `* Re: eficient float sign routinefir
||    `- Re: eficient float sign routinefir
|`* Re: eficient float sign routineTim Rentsch
| +* Re: eficient float sign routinefir
| |`* Re: eficient float sign routinefir
| | `* Re: eficient float sign routinefir
| |  `- Re: eficient float sign routinefir
| `- Re: eficient float sign routineBen
+* Re: eficient float sign routineAndrey Tarasevich
|+* Re: eficient float sign routineRichard Damon
||`- Re: eficient float sign routineAndrey Tarasevich
|`* Re: eficient float sign routinefir
| `* Re: eficient float sign routinefir
|  `* Re: eficient float sign routinefir
|   `* Re: eficient float sign routinefir
|    `- Re: eficient float sign routinefir
`* Re: eficient float sign routineBonita Montero
 +* Re: eficient float sign routineBonita Montero
 |+* Re: eficient float sign routineBonita Montero
 ||`* Re: eficient float sign routineKaz Kylheku
 || `* Re: eficient float sign routineBonita Montero
 ||  `* Re: eficient float sign routineÖö Tiib
 ||   `* Re: eficient float sign routineBonita Montero
 ||    `* Re: eficient float sign routinefir
 ||     `- Re: eficient float sign routineBonita Montero
 |`* Re: eficient float sign routinefir
 | `* Re: eficient float sign routineBonita Montero
 |  `* Re: eficient float sign routinefir
 |   +* Re: eficient float sign routinefir
 |   |+* Re: eficient float sign routinefir
 |   ||`* Re: eficient float sign routineBonita Montero
 |   || `- Re: eficient float sign routinefir
 |   |+* Re: eficient float sign routineBonita Montero
 |   ||`- Re: eficient float sign routinefir
 |   |`* Re: eficient float sign routinefir
 |   | +- Re: eficient float sign routinefir
 |   | +* Re: eficient float sign routinefir
 |   | |`* Re: eficient float sign routinefir
 |   | | `- Re: eficient float sign routinefir
 |   | `* Re: eficient float sign routineBonita Montero
 |   |  `* Re: eficient float sign routinefir
 |   |   `- Re: eficient float sign routinefir
 |   `- Re: eficient float sign routineBonita Montero
 `* Re: eficient float sign routineScott Lurndal
  +* Re: eficient float sign routineManfred
  |`* Re: eficient float sign routineBen
  | +* Re: eficient float sign routineKeith Thompson
  | |`- Re: eficient float sign routineBen
  | `* Re: eficient float sign routineManfred
  |  `* Re: eficient float sign routineTim Rentsch
  |   `* Re: eficient float sign routinejak
  |    `* Re: eficient float sign routineTim Rentsch
  |     `* Re: eficient float sign routinejak
  |      `* Re: eficient float sign routineTim Rentsch
  |       `* Re: eficient float sign routinejak
  |        `* Re: eficient float sign routineBen
  |         `- Re: eficient float sign routinejak
  `- Re: eficient float sign routineBonita Montero

Pages:123
Re: eficient float sign routine

<6c2905cf-b13f-4a58-8065-78c89af225b5n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21791&group=comp.lang.c#21791

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1016:b0:303:bc39:3225 with SMTP id d22-20020a05622a101600b00303bc393225mr748222qte.307.1653825037688;
Sun, 29 May 2022 04:50:37 -0700 (PDT)
X-Received: by 2002:a05:6214:194f:b0:461:b6e5:79b6 with SMTP id
q15-20020a056214194f00b00461b6e579b6mr41770975qvk.60.1653825037506; Sun, 29
May 2022 04:50:37 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.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: Sun, 29 May 2022 04:50:37 -0700 (PDT)
In-Reply-To: <7fbe61f5-d94e-41b6-86c3-d9f4d48fc9b6n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.153; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.153
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6tmt6$d76$1@dont-email.me> <t6tnb4$fe1$1@dont-email.me> <558d49fa-47aa-4b13-b5c4-937ce8dd8c6bn@googlegroups.com>
<t6vfv8$dc$2@dont-email.me> <5921d9d0-166a-4b4a-ba01-ef19995511f5n@googlegroups.com>
<c88b592d-012c-4c6c-81cc-6f0633b01a57n@googlegroups.com> <69019d10-4416-4e42-80ca-69b58c74af3bn@googlegroups.com>
<7fbe61f5-d94e-41b6-86c3-d9f4d48fc9b6n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6c2905cf-b13f-4a58-8065-78c89af225b5n@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Sun, 29 May 2022 11:50:37 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3904
 by: fir - Sun, 29 May 2022 11:50 UTC

niedziela, 29 maja 2022 o 13:05:30 UTC+2 fir napisał(a):
> niedziela, 29 maja 2022 o 12:57:48 UTC+2 fir napisał(a):
> > niedziela, 29 maja 2022 o 12:08:21 UTC+2 fir napisał(a):
> > >
> > > like:
> > > x = sign(d)*d*d
> > >
> >
> > in fact fabs could go here and i do some tests
> >
> > void RunFrame(int advance)
> > {
> > ClearFrameData(0x505077);
> > sum = 0;
> > for(float f= -333333.33; f< 333333.3; f+=0.111)
> > // sum = -copysignf(1,f)*f*f; //26 ms //29 ms
> > sum = -fabs(f)*f; //26 ms //34 ms
> >
> > DrawSomeText2(0xff0000, 10 , 30, "aaaa %f", sum);
> > }
> >
> > i test it pitting some dosed in frame ofthe game as my little library has a built in plot
> > showing frame times so i may see olways live what my game changes effect on frame times
> >
> > i tested it on gcc 5 and gcc 10 - i more use gcc5 for some reason i dont remember which one
> > maybe it compiles faster or maybe becouse another reasons (various version of compilers sometimes
> > compiel some things better and some other worse so its the best to have couple and test them all
> > from time to time)
> >
> > some may also test it of have windows, only need to have mingw/tdm installed and put path to in tn compile.vat first line
> >
> > http://filesharing24.com/d/Ofo
> btw if some would like test it when runing it press f4 and hold, it sets sleep in the loop to zero so only there the value is real (sleep is added to not make cpu work on full load, and teh counter counts difference in time including all round (including sleep) but in case of testing one want to sleep zero to see minimal frame time)

forgot to mention to show a plot one ned to toggle f2

overally its quite weird how times switch randomly form version to wersion,
there is kinda joke that may be used when talking with ponys who generally thinks hard that
newer version of soft is always better - the joke would be to say that never version has 50% chance
to be better and 50% chance to be worse - i dont use that joke but it seems that reall life resembles this joke a lot

for eample when compiling my library (with some initial scene) with gcc 4.7 30 ms... gcc5.1 25 ms ... gcc10.3 28 ms

Re: eficient float sign routine

<ad739cb4-0710-4773-a869-2f6d3adaff5cn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21792&group=comp.lang.c#21792

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:300d:b0:462:1c83:2f44 with SMTP id ke13-20020a056214300d00b004621c832f44mr34325373qvb.41.1653825310941;
Sun, 29 May 2022 04:55:10 -0700 (PDT)
X-Received: by 2002:ac8:5903:0:b0:2fb:8c1c:ac68 with SMTP id
3-20020ac85903000000b002fb8c1cac68mr16375654qty.77.1653825310782; Sun, 29 May
2022 04:55:10 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.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: Sun, 29 May 2022 04:55:10 -0700 (PDT)
In-Reply-To: <6c2905cf-b13f-4a58-8065-78c89af225b5n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.153; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.153
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6tmt6$d76$1@dont-email.me> <t6tnb4$fe1$1@dont-email.me> <558d49fa-47aa-4b13-b5c4-937ce8dd8c6bn@googlegroups.com>
<t6vfv8$dc$2@dont-email.me> <5921d9d0-166a-4b4a-ba01-ef19995511f5n@googlegroups.com>
<c88b592d-012c-4c6c-81cc-6f0633b01a57n@googlegroups.com> <69019d10-4416-4e42-80ca-69b58c74af3bn@googlegroups.com>
<7fbe61f5-d94e-41b6-86c3-d9f4d48fc9b6n@googlegroups.com> <6c2905cf-b13f-4a58-8065-78c89af225b5n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ad739cb4-0710-4773-a869-2f6d3adaff5cn@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Sun, 29 May 2022 11:55:10 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4220
 by: fir - Sun, 29 May 2022 11:55 UTC

niedziela, 29 maja 2022 o 13:50:44 UTC+2 fir napisał(a):
> niedziela, 29 maja 2022 o 13:05:30 UTC+2 fir napisał(a):
> > niedziela, 29 maja 2022 o 12:57:48 UTC+2 fir napisał(a):
> > > niedziela, 29 maja 2022 o 12:08:21 UTC+2 fir napisał(a):
> > > >
> > > > like:
> > > > x = sign(d)*d*d
> > > >
> > >
> > > in fact fabs could go here and i do some tests
> > >
> > > void RunFrame(int advance)
> > > {
> > > ClearFrameData(0x505077);
> > > sum = 0;
> > > for(float f= -333333.33; f< 333333.3; f+=0.111)
> > > // sum = -copysignf(1,f)*f*f; //26 ms //29 ms
> > > sum = -fabs(f)*f; //26 ms //34 ms
> > >
> > > DrawSomeText2(0xff0000, 10 , 30, "aaaa %f", sum);
> > > }
> > >
> > > i test it pitting some dosed in frame ofthe game as my little library has a built in plot
> > > showing frame times so i may see olways live what my game changes effect on frame times
> > >
> > > i tested it on gcc 5 and gcc 10 - i more use gcc5 for some reason i dont remember which one
> > > maybe it compiles faster or maybe becouse another reasons (various version of compilers sometimes
> > > compiel some things better and some other worse so its the best to have couple and test them all
> > > from time to time)
> > >
> > > some may also test it of have windows, only need to have mingw/tdm installed and put path to in tn compile.vat first line
> > >
> > > http://filesharing24.com/d/Ofo
> > btw if some would like test it when runing it press f4 and hold, it sets sleep in the loop to zero so only there the value is real (sleep is added to not make cpu work on full load, and teh counter counts difference in time including all round (including sleep) but in case of testing one want to sleep zero to see minimal frame time)
> forgot to mention to show a plot one ned to toggle f2
>
> overally its quite weird how times switch randomly form version to wersion,
> there is kinda joke that may be used when talking with ponys who generally thinks hard that
> newer version of soft is always better - the joke would be to say that never version has 50% chance
> to be better and 50% chance to be worse - i dont use that joke but it seems that reall life resembles this joke a lot
>
> for eample when compiling my library (with some initial scene) with gcc 4..9 30 ms... gcc5.1 25 ms ... gcc10.3 28 ms

with this sign example its in fact oposite 4.7 was 26 ms same as 10.3 when 5.1 was 29ms and 34 ms

Re: eficient float sign routine

<t7039s$1g78$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21793&group=comp.lang.c#21793

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Puiiztk9lHEEQC0y3uUjRA.user.46.165.242.75.POSTED!not-for-mail
From: non...@add.invalid (Manfred)
Newsgroups: comp.lang.c
Subject: Re: eficient float sign routine
Date: Sun, 29 May 2022 17:25:48 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t7039s$1g78$1@gioia.aioe.org>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6tmt6$d76$1@dont-email.me> <wXukK.37418$J0r9.3724@fx11.iad>
<t6u21o$pje$1@gioia.aioe.org> <877d65w6jp.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="49384"; posting-host="Puiiztk9lHEEQC0y3uUjRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Manfred - Sun, 29 May 2022 15:25 UTC

On 5/29/2022 2:01 AM, Ben wrote:
> Manfred <noname@add.invalid> writes:
>
>> On 5/28/2022 9:43 PM, Scott Lurndal wrote:
>>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>>> In a superior language:
>>>>
>>>> #include <cstdint>
>>>> #include <cstring>
>>>> #include <limits>
>>>> #include <concepts>
>>>> #include <type_traits>
>>>>
>>>> template<typename FpType>
>>>> requires (std::same_as<FpType, float> || std::same_as<FpType, double>)
>>>> && std::numeric_limits<FpType>::is_iec559
>>>> std::conditional_t<std::same_as<FpType, float>, std::int32_t,
>>>> std::int64_t> giveSign( FpType value )
>>>> {
>>>> using namespace std;
>>>> conditional_t<std::same_as<FpType, float>, int32_t, int64_t> iValue;
>>>> memcpy( &iValue, &value, sizeof value );
>>>> return iValue;
>>>> }
>>>>
>>>> template
>>>> std::int32_t giveSign( float );
>>>>
>>>>
>>>> template
>>>> std::int64_t giveSign( double );
>>> In an even more superior language.
>>
>> Agreed with the "even superior" part, at least in this case.
>
> Although C++ also has the signbit functions.

Yes, but that comes from <math.h> or <cmath>, which is substantially
equivalent - in other words, this falls into the inclusion of C into C++.
On the other hand, the proposed alternative, C++ template based, is
considerably worse, IMO.

>
>>> #include <math.h>
>>> int main()
>>> {
>>> float_t number = -1.235;
>>> // sign = signbit(number);
>>
>> int sign = signbit(number);
>
> Yes, missing type but also
>
> int sign = signbitf(number);

I can't find a signbitf function or macro in the C or C++ standard.

>
> if likely to be what's wanted, even though float_t is not a standard
> type.

As Keith said, float_t is declared in <math.h> as part of the standard.
I was surprised too.

Anyway, the point stands that simpler solutions are often
> preferable.

Agreed, that is the gist of the "even superior" part.

>
>>> return sign;
>>> }
>

Re: eficient float sign routine

<f14b4f36-e4b9-49c2-87d2-2ec652248282n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21794&group=comp.lang.c#21794

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:66d0:0:b0:6a3:6e94:7794 with SMTP id a199-20020a3766d0000000b006a36e947794mr26693382qkc.526.1653841861801;
Sun, 29 May 2022 09:31:01 -0700 (PDT)
X-Received: by 2002:ac8:7d91:0:b0:2f3:b85b:326d with SMTP id
c17-20020ac87d91000000b002f3b85b326dmr41237718qtd.194.1653841861570; Sun, 29
May 2022 09:31:01 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.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: Sun, 29 May 2022 09:31:01 -0700 (PDT)
In-Reply-To: <0dd29ff5-b525-4d34-aa32-a3b0e41b71c0n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.122; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.122
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6rt70$240$1@dont-email.me> <9d5b3a38-bd37-44ef-9c83-020fc0b0e694n@googlegroups.com>
<0dd29ff5-b525-4d34-aa32-a3b0e41b71c0n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f14b4f36-e4b9-49c2-87d2-2ec652248282n@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Sun, 29 May 2022 16:31:01 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1846
 by: fir - Sun, 29 May 2022 16:31 UTC

ye thinking a bot more on that i think thet simplicity is the most valueable here (probably)

so this IEEE 754 is not good

what is should be:
highest byte exponent (in U2 from +127 to -128 or maybe -127 and -128 would meen inf)
lowest 3 bytes 24bit integer in U2 ...exponent would meen *2^exp

so zero would be 00000000 00000000 00000000 00000000
1 would be 00000000 00000000 00000000 00000001
-1 would be 00000000 11111111 11111111 11111111
1/2 would be 11111111 00000000 00000000 00000001
-1/2 im not sure 11111111 11111111 1111111 1111111
???

Re: eficient float sign routine

<3413e670-3bb5-4ed8-a2d7-a57b2e3f34dcn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21795&group=comp.lang.c#21795

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:4542:b0:6a0:651b:be0b with SMTP id u2-20020a05620a454200b006a0651bbe0bmr34704392qkp.633.1653842191906;
Sun, 29 May 2022 09:36:31 -0700 (PDT)
X-Received: by 2002:a05:6214:5005:b0:461:c843:98e7 with SMTP id
jo5-20020a056214500500b00461c84398e7mr43153890qvb.16.1653842191735; Sun, 29
May 2022 09:36:31 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.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: Sun, 29 May 2022 09:36:31 -0700 (PDT)
In-Reply-To: <f14b4f36-e4b9-49c2-87d2-2ec652248282n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.122; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.122
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6rt70$240$1@dont-email.me> <9d5b3a38-bd37-44ef-9c83-020fc0b0e694n@googlegroups.com>
<0dd29ff5-b525-4d34-aa32-a3b0e41b71c0n@googlegroups.com> <f14b4f36-e4b9-49c2-87d2-2ec652248282n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3413e670-3bb5-4ed8-a2d7-a57b2e3f34dcn@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Sun, 29 May 2022 16:36:31 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2339
 by: fir - Sun, 29 May 2022 16:36 UTC

niedziela, 29 maja 2022 o 18:31:08 UTC+2 fir napisał(a):
> ye thinking a bot more on that i think thet simplicity is the most valueable here (probably)
>
> so this IEEE 754 is not good
>
> what is should be:
> highest byte exponent (in U2 from +127 to -128 or maybe -127 and -128 would meen inf)
> lowest 3 bytes 24bit integer in U2 ...exponent would meen *2^exp
>
> so zero would be 00000000 00000000 00000000 00000000
> 1 would be 00000000 00000000 00000000 00000001
> -1 would be 00000000 11111111 11111111 11111111
> 1/2 would be 11111111 00000000 00000000 00000001
> -1/2 im not sure 11111111 11111111 1111111 1111111
> ???
though im not sure if the dot should be not movd inituially
so 1 should be 00000000 00000000 0001 0000 00000000
1/2 would be 00000000 00000000 0000 1000 00000000

do teh 1/x would be then liek copying bits in reverse? like 13 = 00001101 so 1/13 = 10110000 ??

Re: eficient float sign routine

<d8a147ed-f2c3-4106-955e-24495b8801f9n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21796&group=comp.lang.c#21796

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:b67:b0:45d:db71:9592 with SMTP id ey7-20020a0562140b6700b0045ddb719592mr42636553qvb.128.1653842489504;
Sun, 29 May 2022 09:41:29 -0700 (PDT)
X-Received: by 2002:ad4:5bc7:0:b0:45b:ab2:6d04 with SMTP id
t7-20020ad45bc7000000b0045b0ab26d04mr42346386qvt.75.1653842489335; Sun, 29
May 2022 09:41:29 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.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: Sun, 29 May 2022 09:41:29 -0700 (PDT)
In-Reply-To: <3413e670-3bb5-4ed8-a2d7-a57b2e3f34dcn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.122; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.122
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6rt70$240$1@dont-email.me> <9d5b3a38-bd37-44ef-9c83-020fc0b0e694n@googlegroups.com>
<0dd29ff5-b525-4d34-aa32-a3b0e41b71c0n@googlegroups.com> <f14b4f36-e4b9-49c2-87d2-2ec652248282n@googlegroups.com>
<3413e670-3bb5-4ed8-a2d7-a57b2e3f34dcn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d8a147ed-f2c3-4106-955e-24495b8801f9n@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Sun, 29 May 2022 16:41:29 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2553
 by: fir - Sun, 29 May 2022 16:41 UTC

niedziela, 29 maja 2022 o 18:36:39 UTC+2 fir napisał(a):
> niedziela, 29 maja 2022 o 18:31:08 UTC+2 fir napisał(a):
> > ye thinking a bot more on that i think thet simplicity is the most valueable here (probably)
> >
> > so this IEEE 754 is not good
> >
> > what is should be:
> > highest byte exponent (in U2 from +127 to -128 or maybe -127 and -128 would meen inf)
> > lowest 3 bytes 24bit integer in U2 ...exponent would meen *2^exp
> >
> > so zero would be 00000000 00000000 00000000 00000000
> > 1 would be 00000000 00000000 00000000 00000001
> > -1 would be 00000000 11111111 11111111 11111111
> > 1/2 would be 11111111 00000000 00000000 00000001
> > -1/2 im not sure 11111111 11111111 1111111 1111111
> > ???
> though im not sure if the dot should be not movd inituially
> so 1 should be 00000000 00000000 0001 0000 00000000
> 1/2 would be 00000000 00000000 0000 1000 00000000
>
> do teh 1/x would be then liek copying bits in reverse? like 13 = 00001101 so 1/13 = 10110000 ??

nah it would be only 1/1 +1/4+1/8 = 13/8

Re: eficient float sign routine

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

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21797&group=comp.lang.c#21797

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben)
Newsgroups: comp.lang.c
Subject: Re: eficient float sign routine
Date: Sun, 29 May 2022 19:36:33 +0100
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <87v8touqx9.fsf@bsb.me.uk>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6tmt6$d76$1@dont-email.me> <wXukK.37418$J0r9.3724@fx11.iad>
<t6u21o$pje$1@gioia.aioe.org> <877d65w6jp.fsf@bsb.me.uk>
<87pmjxru6a.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="186fd15395331ee5fbcd6d71035d1d29";
logging-data="15090"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19++eOuHPDlULE/sUC8NZuOmcY32pHzYpU="
Cancel-Lock: sha1:UOZCy5q6qdwXm8FFuWlg7A+rL9U=
sha1:QDN0VWzzoFJYN6xA6HwCM1s9gi4=
X-BSB-Auth: 1.e8e284ee8cdf4b5ae997.20220529193634BST.87v8touqx9.fsf@bsb.me.uk
 by: Ben - Sun, 29 May 2022 18:36 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Ben <ben.usenet@bsb.me.uk> writes:
> [...]
>> Yes, missing type but also
>>
>> int sign = signbitf(number);
>>
>> if likely to be what's wanted, even though float_t is not a standard
>> type. Anyway, the point stands that simpler solutions are often
>> preferable.
>
> Yes, float_t is standard. It's the same as one of the predefined
> floating-point types, depending on the value of FLT_EVAL_METHOD.

Never new that. Thanks.

--
Ben.

Re: eficient float sign routine

<86r143yy86.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21837&group=comp.lang.c#21837

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: eficient float sign routine
Date: Sun, 05 Jun 2022 07:35:37 -0700
Organization: A noiseless patient Spider
Lines: 99
Message-ID: <86r143yy86.fsf@linuxsc.com>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com> <t6tmt6$d76$1@dont-email.me> <wXukK.37418$J0r9.3724@fx11.iad> <t6u21o$pje$1@gioia.aioe.org> <877d65w6jp.fsf@bsb.me.uk> <t7039s$1g78$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="1e3de3f3b17d2a32ddf0f156c04f9d14";
logging-data="12455"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18nZZSE2j1YbHfLeNKKwYe+JKq4CFtZfc8="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:31WFZ66/51Hyyhn48OcKtBKZVto=
sha1:t1JHEC/4kajTiiHwq1C07PFlY54=
 by: Tim Rentsch - Sun, 5 Jun 2022 14:35 UTC

Manfred <noname@add.invalid> writes:

> On 5/29/2022 2:01 AM, Ben wrote:
>
>> Manfred <noname@add.invalid> writes:
>>
>>> On 5/28/2022 9:43 PM, Scott Lurndal wrote:
>>>
>>>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>>>
>>>>> In a superior language:
>>>>>
>>>>> #include <cstdint>
>>>>> #include <cstring>
>>>>> #include <limits>
>>>>> #include <concepts>
>>>>> #include <type_traits>
>>>>>
>>>>> template<typename FpType>
>>>>> requires (std::same_as<FpType, float> || std::same_as<FpType, double>)
>>>>> && std::numeric_limits<FpType>::is_iec559
>>>>> std::conditional_t<std::same_as<FpType, float>, std::int32_t,
>>>>> std::int64_t> giveSign( FpType value )
>>>>> {
>>>>> using namespace std;
>>>>> conditional_t<std::same_as<FpType, float>, int32_t, int64_t> iValue;
>>>>> memcpy( &iValue, &value, sizeof value );
>>>>> return iValue;
>>>>> }
>>>>>
>>>>> template
>>>>> std::int32_t giveSign( float );
>>>>>
>>>>>
>>>>> template
>>>>> std::int64_t giveSign( double );
>>>>
>>>> In an even more superior language.
>>>
>>> Agreed with the "even superior" part, at least in this case.
>>
>> Although C++ also has the signbit functions.
>
> Yes, but that comes from <math.h> or <cmath>, which is substantially
> equivalent - in other words, this falls into the inclusion of C into
> C++.
> On the other hand, the proposed alternative, C++ template based, is
> considerably worse, IMO.
>
>>>> #include <math.h>
>>>> int main()
>>>> {
>>>> float_t number = -1.235;
>>>> // sign = signbit(number);
>>>
>>> int sign = signbit(number);
>>
>> Yes, missing type but also
>>
>> int sign = signbitf(number);
>
> I can't find a signbitf function or macro in the C or C++ standard.

Right. C defines a signbit() macro; C++ defines a signbit()
function, overloaded for each of the usual floating-point types.

>> if likely to be what's wanted, even though float_t is not a standard
>> type.
>
> As Keith said, float_t is declared in <math.h> as part of the
> standard. I was surprised too.
>
>> Anyway, the point stands that simpler solutions are often
>> preferable.
>
> Agreed, that is the gist of the "even superior" part.

I'm all in favor of simple solutions, but to count as a solution
the code needs to supply the behavior desired. The code from
Bonita gives a several-valued result (actually a many-valued
result, but the key thing is that it is more than binary).
Apparently what is being looked for is a "signum" function for
floating point, giving -1, 0, or 1, according to whether its
argument is, respectively, less than, equal to, or greater than
zero. This behavior can be supplied with a single (and simple)
function definition (and incidentally one that works regardless
of how floating-point numbers are represented):

#include <math.h>

int
fp_signum( long double x ){
return x ? signbit(x) ? -1 : 1 : 0;
}

If writing in C++, we might need a different #include (I have not
investigated that), and we might want to define two more overloaded
versions, for double and float, if that matters for some reason
(such as performance considerations).

Re: eficient float sign routine

<t7iv70$qd9$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21839&group=comp.lang.c#21839

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!dmlM6cj6giYBRBJohxz2Ng.user.46.165.242.91.POSTED!not-for-mail
From: nos...@please.ty (jak)
Newsgroups: comp.lang.c
Subject: Re: eficient float sign routine
Date: Sun, 5 Jun 2022 21:12:33 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t7iv70$qd9$1@gioia.aioe.org>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6tmt6$d76$1@dont-email.me> <wXukK.37418$J0r9.3724@fx11.iad>
<t6u21o$pje$1@gioia.aioe.org> <877d65w6jp.fsf@bsb.me.uk>
<t7039s$1g78$1@gioia.aioe.org> <86r143yy86.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="27049"; posting-host="dmlM6cj6giYBRBJohxz2Ng.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
X-Notice: Filtered by postfilter v. 0.9.2
 by: jak - Sun, 5 Jun 2022 19:12 UTC

Il 05/06/2022 16:35, Tim Rentsch ha scritto:
> Manfred <noname@add.invalid> writes:
>
>> On 5/29/2022 2:01 AM, Ben wrote:
>>
>>> Manfred <noname@add.invalid> writes:
>>>
>>>> On 5/28/2022 9:43 PM, Scott Lurndal wrote:
>>>>
>>>>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>>>>
>>>>>> In a superior language:
>>>>>>
>>>>>> #include <cstdint>
>>>>>> #include <cstring>
>>>>>> #include <limits>
>>>>>> #include <concepts>
>>>>>> #include <type_traits>
>>>>>>
>>>>>> template<typename FpType>
>>>>>> requires (std::same_as<FpType, float> || std::same_as<FpType, double>)
>>>>>> && std::numeric_limits<FpType>::is_iec559
>>>>>> std::conditional_t<std::same_as<FpType, float>, std::int32_t,
>>>>>> std::int64_t> giveSign( FpType value )
>>>>>> {
>>>>>> using namespace std;
>>>>>> conditional_t<std::same_as<FpType, float>, int32_t, int64_t> iValue;
>>>>>> memcpy( &iValue, &value, sizeof value );
>>>>>> return iValue;
>>>>>> }
>>>>>>
>>>>>> template
>>>>>> std::int32_t giveSign( float );
>>>>>>
>>>>>>
>>>>>> template
>>>>>> std::int64_t giveSign( double );
>>>>>
>>>>> In an even more superior language.
>>>>
>>>> Agreed with the "even superior" part, at least in this case.
>>>
>>> Although C++ also has the signbit functions.
>>
>> Yes, but that comes from <math.h> or <cmath>, which is substantially
>> equivalent - in other words, this falls into the inclusion of C into
>> C++.
>> On the other hand, the proposed alternative, C++ template based, is
>> considerably worse, IMO.
>>
>>>>> #include <math.h>
>>>>> int main()
>>>>> {
>>>>> float_t number = -1.235;
>>>>> // sign = signbit(number);
>>>>
>>>> int sign = signbit(number);
>>>
>>> Yes, missing type but also
>>>
>>> int sign = signbitf(number);
>>
>> I can't find a signbitf function or macro in the C or C++ standard.
>
> Right. C defines a signbit() macro; C++ defines a signbit()
> function, overloaded for each of the usual floating-point types.
>
>>> if likely to be what's wanted, even though float_t is not a standard
>>> type.
>>
>> As Keith said, float_t is declared in <math.h> as part of the
>> standard. I was surprised too.
>>
>>> Anyway, the point stands that simpler solutions are often
>>> preferable.
>>
>> Agreed, that is the gist of the "even superior" part.
>
> I'm all in favor of simple solutions, but to count as a solution
> the code needs to supply the behavior desired. The code from
> Bonita gives a several-valued result (actually a many-valued
> result, but the key thing is that it is more than binary).
> Apparently what is being looked for is a "signum" function for
> floating point, giving -1, 0, or 1, according to whether its
> argument is, respectively, less than, equal to, or greater than
> zero. This behavior can be supplied with a single (and simple)
> function definition (and incidentally one that works regardless
> of how floating-point numbers are represented):
>
> #include <math.h>
>
> int
> fp_signum( long double x ){
> return x ? signbit(x) ? -1 : 1 : 0;
> }
>
> If writing in C++, we might need a different #include (I have not
> investigated that), and we might want to define two more overloaded
> versions, for double and float, if that matters for some reason
> (such as performance considerations).

mmmh ... so in C, using a macro like this, you could make the floating
point type generic:

#define my_sign(x) ((x == 0.) ? 0 : (((unsigned char *)&x)[sizeof(x) -
1] & 0x80) ? -1 : 1)

Re: eficient float sign routine

<86mteqzxbp.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21841&group=comp.lang.c#21841

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: eficient float sign routine
Date: Sun, 05 Jun 2022 13:09:46 -0700
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <86mteqzxbp.fsf@linuxsc.com>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com> <t6tmt6$d76$1@dont-email.me> <wXukK.37418$J0r9.3724@fx11.iad> <t6u21o$pje$1@gioia.aioe.org> <877d65w6jp.fsf@bsb.me.uk> <t7039s$1g78$1@gioia.aioe.org> <86r143yy86.fsf@linuxsc.com> <t7iv70$qd9$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="1e3de3f3b17d2a32ddf0f156c04f9d14";
logging-data="13935"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19YYSIvRpy1FTh9zvz/eZaITDiNdL9ARHo="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:bJqXq93r956WKjZzYtM26q0fWOU=
sha1:4mrXUICXKUOu9ToZkZfxE8pBot8=
 by: Tim Rentsch - Sun, 5 Jun 2022 20:09 UTC

jak <nospam@please.ty> writes:

> Il 05/06/2022 16:35, Tim Rentsch ha scritto:

[...]

>> Apparently what is being looked for is a "signum" function for
>> floating point, giving -1, 0, or 1, according to whether its
>> argument is, respectively, less than, equal to, or greater than
>> zero. This behavior can be supplied with a single (and simple)
>> function definition (and incidentally one that works regardless
>> of how floating-point numbers are represented):
>>
>> #include <math.h>
>>
>> int
>> fp_signum( long double x ){
>> return x ? signbit(x) ? -1 : 1 : 0;
>> }
>>
>> [...]
>
> mmmh ... so in C, using a macro like this, you could make the floating
> point type generic: [white space added to avoid long lines]
>
> #define my_sign(x) ( \
> (x == 0.) ? 0 : \
> (((unsigned char *)&x)[sizeof(x) - 1] & 0x80) ? -1 : 1 \
> )

Yes you could.. if you aren't worried about portability, and
you aren't too fussy about getting compilation errors for some
floating-point arguments, and you don't mind getting wrong
answers in some cases.

(Also, macro parameters should be enclosed in parentheses to
avoid unintended parsings. But the problems mentioned remain
even if the macro definition is changed to follow that rule.)

Re: eficient float sign routine

<t7kc77$1dln$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21847&group=comp.lang.c#21847

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!WxbkwcuZNGGKyExlHcZcWA.user.46.165.242.91.POSTED!not-for-mail
From: nos...@please.ty (jak)
Newsgroups: comp.lang.c
Subject: Re: eficient float sign routine
Date: Mon, 6 Jun 2022 10:00:39 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t7kc77$1dln$1@gioia.aioe.org>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6tmt6$d76$1@dont-email.me> <wXukK.37418$J0r9.3724@fx11.iad>
<t6u21o$pje$1@gioia.aioe.org> <877d65w6jp.fsf@bsb.me.uk>
<t7039s$1g78$1@gioia.aioe.org> <86r143yy86.fsf@linuxsc.com>
<t7iv70$qd9$1@gioia.aioe.org> <86mteqzxbp.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="46775"; posting-host="WxbkwcuZNGGKyExlHcZcWA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
X-Notice: Filtered by postfilter v. 0.9.2
 by: jak - Mon, 6 Jun 2022 08:00 UTC

Il 05/06/2022 22:09, Tim Rentsch ha scritto:
> jak <nospam@please.ty> writes:
>
>> Il 05/06/2022 16:35, Tim Rentsch ha scritto:
>
> [...]
>
>>> Apparently what is being looked for is a "signum" function for
>>> floating point, giving -1, 0, or 1, according to whether its
>>> argument is, respectively, less than, equal to, or greater than
>>> zero. This behavior can be supplied with a single (and simple)
>>> function definition (and incidentally one that works regardless
>>> of how floating-point numbers are represented):
>>>
>>> #include <math.h>
>>>
>>> int
>>> fp_signum( long double x ){
>>> return x ? signbit(x) ? -1 : 1 : 0;
>>> }
>>>
>>> [...]
>>
>> mmmh ... so in C, using a macro like this, you could make the floating
>> point type generic: [white space added to avoid long lines]
>>
>> #define my_sign(x) ( \
>> (x == 0.) ? 0 : \
>> (((unsigned char *)&x)[sizeof(x) - 1] & 0x80) ? -1 : 1 \
>> )
>
> Yes you could.. if you aren't worried about portability, and
> you aren't too fussy about getting compilation errors for some
> floating-point arguments, and you don't mind getting wrong
> answers in some cases.
>
> (Also, macro parameters should be enclosed in parentheses to
> avoid unintended parsings. But the problems mentioned remain
> even if the macro definition is changed to follow that rule.)

then changing the macro like this:

#define my_sign(v) \
({ \
long double x = (long double)(v); \
int r = 0; \
if(x != 0.) \
r = (x > 0.) ? 1 : -1; \
r; \
})

and then by casting to the largest of the float types and using only
boolean logic with a macro you can test all the float types that have a
size smaller than or equal to the largest of them and the representation
of the types is not important. If there are further problems I have not
noticed them English is not my language.

Re: eficient float sign routine

<86ilpdz786.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21859&group=comp.lang.c#21859

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: eficient float sign routine
Date: Mon, 06 Jun 2022 16:45:45 -0700
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <86ilpdz786.fsf@linuxsc.com>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com> <t6tmt6$d76$1@dont-email.me> <wXukK.37418$J0r9.3724@fx11.iad> <t6u21o$pje$1@gioia.aioe.org> <877d65w6jp.fsf@bsb.me.uk> <t7039s$1g78$1@gioia.aioe.org> <86r143yy86.fsf@linuxsc.com> <t7iv70$qd9$1@gioia.aioe.org> <86mteqzxbp.fsf@linuxsc.com> <t7kc77$1dln$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="8d3b78834a5fcc019414bbade7c1b111";
logging-data="17104"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18iLfSDy1Yhzuqqj2tuHzBf25twYBa1mEY="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:7+uBsE/vOpIzq/AfC+yITPKuuoo=
sha1:4+SLc0wWPinE6zEE8OpuC3b2RHE=
 by: Tim Rentsch - Mon, 6 Jun 2022 23:45 UTC

jak <nospam@please.ty> writes:

> Il 05/06/2022 22:09, Tim Rentsch ha scritto:
>
>> jak <nospam@please.ty> writes:
>>
>>> Il 05/06/2022 16:35, Tim Rentsch ha scritto:
>>
>> [...]
>>
>>>> Apparently what is being looked for is a "signum" function for
>>>> floating point, giving -1, 0, or 1, according to whether its
>>>> argument is, respectively, less than, equal to, or greater than
>>>> zero. This behavior can be supplied with a single (and simple)
>>>> function definition (and incidentally one that works regardless
>>>> of how floating-point numbers are represented):
>>>>
>>>> #include <math.h>
>>>>
>>>> int
>>>> fp_signum( long double x ){
>>>> return x ? signbit(x) ? -1 : 1 : 0;
>>>> }
>>>>
>>>> [...]
>>>
>>> mmmh ... so in C, using a macro like this, you could make the floating
>>> point type generic: [white space added to avoid long lines]
>>>
>>> #define my_sign(x) ( \
>>> (x == 0.) ? 0 : \
>>> (((unsigned char *)&x)[sizeof(x) - 1] & 0x80) ? -1 : 1 \
>>> )
>>
>> Yes you could.. if you aren't worried about portability, and
>> you aren't too fussy about getting compilation errors for some
>> floating-point arguments, and you don't mind getting wrong
>> answers in some cases.
>>
>> (Also, macro parameters should be enclosed in parentheses to
>> avoid unintended parsings. But the problems mentioned remain
>> even if the macro definition is changed to follow that rule.)
>
> then changing the macro like this:
>
> #define my_sign(v) \
> ({ \
> long double x = (long double)(v); \
> int r = 0; \
> if(x != 0.) \
> r = (x > 0.) ? 1 : -1; \
> r; \
> })
>
> and then by casting to the largest of the float types and using
> only boolean logic with a macro you can test all the float types
> that have a size smaller than or equal to the largest of them and
> the representation of the types is not important. If there are
> further problems I have not noticed them English is not my
> language.

This macro is better than the last one, but it's more complicated
than it has to be, and it needs a non-standard extension to work.

Using a function like the one shown above allows the code to be
standard ISO C, which is an important advantage. If performance
matters the function can be declared 'static inline', which is
likely to give the same performance as a macro expansion.

Re: eficient float sign routine

<t7mqb7$15ns$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21860&group=comp.lang.c#21860

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!J3POK5jHbC9p2Rv3BvEq/Q.user.46.165.242.91.POSTED!not-for-mail
From: nos...@please.ty (jak)
Newsgroups: comp.lang.c
Subject: Re: eficient float sign routine
Date: Tue, 7 Jun 2022 08:14:00 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t7mqb7$15ns$1@gioia.aioe.org>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6tmt6$d76$1@dont-email.me> <wXukK.37418$J0r9.3724@fx11.iad>
<t6u21o$pje$1@gioia.aioe.org> <877d65w6jp.fsf@bsb.me.uk>
<t7039s$1g78$1@gioia.aioe.org> <86r143yy86.fsf@linuxsc.com>
<t7iv70$qd9$1@gioia.aioe.org> <86mteqzxbp.fsf@linuxsc.com>
<t7kc77$1dln$1@gioia.aioe.org> <86ilpdz786.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="38652"; posting-host="J3POK5jHbC9p2Rv3BvEq/Q.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
X-Notice: Filtered by postfilter v. 0.9.2
 by: jak - Tue, 7 Jun 2022 06:14 UTC

Il 07/06/2022 01:45, Tim Rentsch ha scritto:
> This macro is better than the last one, but it's more complicated
> than it has to be, and it needs a non-standard extension to work.
>
> Using a function like the one shown above allows the code to be
> standard ISO C, which is an important advantage. If performance
> matters the function can be declared 'static inline', which is
> likely to give the same performance as a macro expansion.

you are right, but this macro has the advantage that it can be used with
all numeric types and not just floats. sometimes accepting compromises
can be beneficial.

cheers

Re: eficient float sign routine

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

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21861&group=comp.lang.c#21861

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben)
Newsgroups: comp.lang.c
Subject: Re: eficient float sign routine
Date: Tue, 07 Jun 2022 11:56:39 +0100
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <87o7z4eo7s.fsf@bsb.me.uk>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6tmt6$d76$1@dont-email.me> <wXukK.37418$J0r9.3724@fx11.iad>
<t6u21o$pje$1@gioia.aioe.org> <877d65w6jp.fsf@bsb.me.uk>
<t7039s$1g78$1@gioia.aioe.org> <86r143yy86.fsf@linuxsc.com>
<t7iv70$qd9$1@gioia.aioe.org> <86mteqzxbp.fsf@linuxsc.com>
<t7kc77$1dln$1@gioia.aioe.org> <86ilpdz786.fsf@linuxsc.com>
<t7mqb7$15ns$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="259ba6281fbdf954c23580d7b6e12aa3";
logging-data="26173"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+K5Sbwp8pqAh37pCEec+LoeW9V0I7btCs="
Cancel-Lock: sha1:vIvNoUDeWZmq/oNprd1atgoD4tk=
sha1:2PxIWPOM7ZwghCKz/qX1Hs4BYIM=
X-BSB-Auth: 1.22dd3066d2675319a742.20220607115639BST.87o7z4eo7s.fsf@bsb.me.uk
 by: Ben - Tue, 7 Jun 2022 10:56 UTC

jak <nospam@please.ty> writes:

> Il 07/06/2022 01:45, Tim Rentsch ha scritto:
>> This macro is better than the last one, but it's more complicated
>> than it has to be, and it needs a non-standard extension to work.
>> Using a function like the one shown above allows the code to be
>> standard ISO C, which is an important advantage. If performance
>> matters the function can be declared 'static inline', which is
>> likely to give the same performance as a macro expansion.
>
> you are right, but this macro has the advantage that it can be used with
> all numeric types and not just floats.

So can Tim's function.

> sometimes accepting compromises can be beneficial.

Sure, but there's no trade-off here.

--
Ben.

Re: eficient float sign routine

<t7o07t$1fmj$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21862&group=comp.lang.c#21862

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!H41EeSQGAr5umFOrXRUjgg.user.46.165.242.91.POSTED!not-for-mail
From: nos...@please.ty (jak)
Newsgroups: comp.lang.c
Subject: Re: eficient float sign routine
Date: Tue, 7 Jun 2022 19:00:47 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t7o07t$1fmj$1@gioia.aioe.org>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6tmt6$d76$1@dont-email.me> <wXukK.37418$J0r9.3724@fx11.iad>
<t6u21o$pje$1@gioia.aioe.org> <877d65w6jp.fsf@bsb.me.uk>
<t7039s$1g78$1@gioia.aioe.org> <86r143yy86.fsf@linuxsc.com>
<t7iv70$qd9$1@gioia.aioe.org> <86mteqzxbp.fsf@linuxsc.com>
<t7kc77$1dln$1@gioia.aioe.org> <86ilpdz786.fsf@linuxsc.com>
<t7mqb7$15ns$1@gioia.aioe.org> <87o7z4eo7s.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="48851"; posting-host="H41EeSQGAr5umFOrXRUjgg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
X-Notice: Filtered by postfilter v. 0.9.2
 by: jak - Tue, 7 Jun 2022 17:00 UTC

Il 07/06/2022 12:56, Ben ha scritto:
> jak <nospam@please.ty> writes:
>
>> Il 07/06/2022 01:45, Tim Rentsch ha scritto:
>>> This macro is better than the last one, but it's more complicated
>>> than it has to be, and it needs a non-standard extension to work.
>>> Using a function like the one shown above allows the code to be
>>> standard ISO C, which is an important advantage. If performance
>>> matters the function can be declared 'static inline', which is
>>> likely to give the same performance as a macro expansion.
>>
>> you are right, but this macro has the advantage that it can be used with
>> all numeric types and not just floats.
>
> So can Tim's function.
>
>> sometimes accepting compromises can be beneficial.
>
> Sure, but there's no trade-off here.
>

oh i know but i also know that among so many languages, this is the
least suitable for following standards and therefore i shut myself up.

Pages:123
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor