Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

<wiggy> in a stunning new move I actually tested this upload


devel / comp.lang.c / 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
eficient float sign routine

<a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:d4d:b0:462:4986:f9bd with SMTP id 13-20020a0562140d4d00b004624986f9bdmr9204597qvr.70.1653473361451;
Wed, 25 May 2022 03:09:21 -0700 (PDT)
X-Received: by 2002:a05:620a:3713:b0:6a5:79c7:f4a4 with SMTP id
de19-20020a05620a371300b006a579c7f4a4mr4327304qkb.767.1653473361287; Wed, 25
May 2022 03:09:21 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.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, 25 May 2022 03:09:21 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.80; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.80
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
Subject: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 25 May 2022 10:09:21 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1255
 by: fir - Wed, 25 May 2022 10:09 UTC

is there some ?
people seem tend to use

inline float sign (float x) { return (x > 0) - (x < 0); }

but im not sure if it is efficient
afaik float standard says that sign bit is the highest bit ot 32bit
representation so maybe something based on this?

but what exactly?

Re: eficient float sign routine

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

  copy mid

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

  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: Wed, 25 May 2022 11:45:35 +0100
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <87ee0hyjow.fsf@bsb.me.uk>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="059b08398b24e05976ef222020b02576";
logging-data="14873"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18pkU3iL7EzXf0g0K//coCeINsB7b6RtYA="
Cancel-Lock: sha1:KTrob5/4nRLzAu2HJ7DDduDlOEs=
sha1:Q5iPgc6JkHfjIIPKhFuKhYz8ASw=
X-BSB-Auth: 1.96c75e0c95b331811bfd.20220525114535BST.87ee0hyjow.fsf@bsb.me.uk
 by: Ben - Wed, 25 May 2022 10:45 UTC

fir <profesor.fir@gmail.com> writes:

> is there some ?
> people seem tend to use
>
> inline float sign (float x) { return (x > 0) - (x < 0); }

Standard C has copysign. A call to your sign(f) function is equivalent
to copysign(1, f).

There is also a standard signbit macro that returns 0/1 depending on the
sign of the argument. These two treat NaNs differently.

--
Ben.

Re: eficient float sign routine

<2677cd65-93b9-407b-9966-7815ed205275n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ad4:5962:0:b0:462:11fe:b67c with SMTP id eq2-20020ad45962000000b0046211feb67cmr19587720qvb.50.1653479224720;
Wed, 25 May 2022 04:47:04 -0700 (PDT)
X-Received: by 2002:a05:622a:155:b0:2f9:11a1:85c7 with SMTP id
v21-20020a05622a015500b002f911a185c7mr21803674qtw.543.1653479224540; Wed, 25
May 2022 04:47:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.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, 25 May 2022 04:47:04 -0700 (PDT)
In-Reply-To: <87ee0hyjow.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.97; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.97
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com> <87ee0hyjow.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2677cd65-93b9-407b-9966-7815ed205275n@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 25 May 2022 11:47:04 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1866
 by: fir - Wed, 25 May 2022 11:47 UTC

środa, 25 maja 2022 o 12:45:50 UTC+2 Ben napisał(a):
> fir <profes...@gmail.com> writes:
>
> > is there some ?
> > people seem tend to use
> >
> > inline float sign (float x) { return (x > 0) - (x < 0); }
> Standard C has copysign. A call to your sign(f) function is equivalent
> to copysign(1, f).
>
> There is also a standard signbit macro that returns 0/1 depending on the
> sign of the argument. These two treat NaNs differently.
>
ok i will see, though it would be better tho have normal functions to not add/multiply
not quite necessary references

Re: eficient float sign routine

<b7f5d0bd-a13b-4df1-8ccf-8fb29fc3124an@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:5fd3:0:b0:2f9:36c8:ea31 with SMTP id k19-20020ac85fd3000000b002f936c8ea31mr11113830qta.557.1653480432172;
Wed, 25 May 2022 05:07:12 -0700 (PDT)
X-Received: by 2002:a05:6214:626:b0:462:43b4:8491 with SMTP id
a6-20020a056214062600b0046243b48491mr11196247qvx.110.1653480432012; Wed, 25
May 2022 05:07:12 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.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, 25 May 2022 05:07:11 -0700 (PDT)
In-Reply-To: <2677cd65-93b9-407b-9966-7815ed205275n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.97; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.97
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<87ee0hyjow.fsf@bsb.me.uk> <2677cd65-93b9-407b-9966-7815ed205275n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b7f5d0bd-a13b-4df1-8ccf-8fb29fc3124an@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 25 May 2022 12:07:12 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2052
 by: fir - Wed, 25 May 2022 12:07 UTC

środa, 25 maja 2022 o 13:47:13 UTC+2 fir napisał(a):
> środa, 25 maja 2022 o 12:45:50 UTC+2 Ben napisał(a):
> > fir <profes...@gmail.com> writes:
> >
> > > is there some ?
> > > people seem tend to use
> > >
> > > inline float sign (float x) { return (x > 0) - (x < 0); }
> > Standard C has copysign. A call to your sign(f) function is equivalent
> > to copysign(1, f).
> >
> > There is also a standard signbit macro that returns 0/1 depending on the
> > sign of the argument. These two treat NaNs differently.
> >
> ok i will see, though it would be better tho have normal functions to not add/multiply
> not quite necessary references

return -2*signbit(x)+1 ;
seem to wrok, though i not tested it except one case

Re: eficient float sign routine

<bd9465aa-4059-4304-8432-e8833ff93e24n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1007:b0:2f3:ce52:25cb with SMTP id d7-20020a05622a100700b002f3ce5225cbmr23951117qte.575.1653481523119;
Wed, 25 May 2022 05:25:23 -0700 (PDT)
X-Received: by 2002:a05:6214:2308:b0:432:e69f:5d71 with SMTP id
gc8-20020a056214230800b00432e69f5d71mr25414560qvb.19.1653481522964; Wed, 25
May 2022 05:25:22 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.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, 25 May 2022 05:25:22 -0700 (PDT)
In-Reply-To: <b7f5d0bd-a13b-4df1-8ccf-8fb29fc3124an@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.170; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.170
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<87ee0hyjow.fsf@bsb.me.uk> <2677cd65-93b9-407b-9966-7815ed205275n@googlegroups.com>
<b7f5d0bd-a13b-4df1-8ccf-8fb29fc3124an@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bd9465aa-4059-4304-8432-e8833ff93e24n@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 25 May 2022 12:25:23 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2563
 by: fir - Wed, 25 May 2022 12:25 UTC

środa, 25 maja 2022 o 14:07:22 UTC+2 fir napisał(a):
> środa, 25 maja 2022 o 13:47:13 UTC+2 fir napisał(a):
> > środa, 25 maja 2022 o 12:45:50 UTC+2 Ben napisał(a):
> > > fir <profes...@gmail.com> writes:
> > >
> > > > is there some ?
> > > > people seem tend to use
> > > >
> > > > inline float sign (float x) { return (x > 0) - (x < 0); }
> > > Standard C has copysign. A call to your sign(f) function is equivalent
> > > to copysign(1, f).
> > >
> > > There is also a standard signbit macro that returns 0/1 depending on the
> > > sign of the argument. These two treat NaNs differently.
> > >
> > ok i will see, though it would be better tho have normal functions to not add/multiply
> > not quite necessary references
> return -2*signbit(x)+1 ;
> seem to wrok, though i not tested it except one case

inline float sign2(float x)
{ return -2*signbit(x)+1 ;
}

inline float sign1(float x)
{ return (x>0)-(x<0);
}

for(float f= -333333.33; f< 333333.3; f+=0.33)
sum += sign2(f);

i tested the efficiency and there is no visible difference here though (about 10 ms each, but i run on quite old machine)

Re: eficient float sign routine

<293f7b29-3796-4d3f-a25c-c2c37d3702c0n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:6ed0:0:b0:2f9:4564:97b5 with SMTP id f16-20020ac86ed0000000b002f9456497b5mr5403156qtv.669.1653481877580;
Wed, 25 May 2022 05:31:17 -0700 (PDT)
X-Received: by 2002:ac8:7d91:0:b0:2f3:b85b:326d with SMTP id
c17-20020ac87d91000000b002f3b85b326dmr24424386qtd.194.1653481877431; Wed, 25
May 2022 05:31:17 -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: Wed, 25 May 2022 05:31:17 -0700 (PDT)
In-Reply-To: <bd9465aa-4059-4304-8432-e8833ff93e24n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.170; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.170
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<87ee0hyjow.fsf@bsb.me.uk> <2677cd65-93b9-407b-9966-7815ed205275n@googlegroups.com>
<b7f5d0bd-a13b-4df1-8ccf-8fb29fc3124an@googlegroups.com> <bd9465aa-4059-4304-8432-e8833ff93e24n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <293f7b29-3796-4d3f-a25c-c2c37d3702c0n@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 25 May 2022 12:31:17 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: fir - Wed, 25 May 2022 12:31 UTC

środa, 25 maja 2022 o 14:25:30 UTC+2 fir napisał(a):
> środa, 25 maja 2022 o 14:07:22 UTC+2 fir napisał(a):
> > środa, 25 maja 2022 o 13:47:13 UTC+2 fir napisał(a):
> > > środa, 25 maja 2022 o 12:45:50 UTC+2 Ben napisał(a):
> > > > fir <profes...@gmail.com> writes:
> > > >
> > > > > is there some ?
> > > > > people seem tend to use
> > > > >
> > > > > inline float sign (float x) { return (x > 0) - (x < 0); }
> > > > Standard C has copysign. A call to your sign(f) function is equivalent
> > > > to copysign(1, f).
> > > >
> > > > There is also a standard signbit macro that returns 0/1 depending on the
> > > > sign of the argument. These two treat NaNs differently.
> > > >
> > > ok i will see, though it would be better tho have normal functions to not add/multiply
> > > not quite necessary references
> > return -2*signbit(x)+1 ;
> > seem to wrok, though i not tested it except one case
> inline float sign2(float x)
> {
> return -2*signbit(x)+1 ;
> }
>
> inline float sign1(float x)
> {
> return (x>0)-(x<0);
> }
>
> for(float f= -333333.33; f< 333333.3; f+=0.33)
> sum += sign2(f);
>
> i tested the efficiency and there is no visible difference here though (about 10 ms each, but i run on quite old machine)

not to say its -2*signbit(x)+1 is not all i woulkd beed as it returns +1 for zero...but if i see no difference i may left he < > version though it looks weird imo

Re: eficient float sign routine

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

  copy mid

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

  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: Wed, 25 May 2022 14:07:07 +0100
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <87wne9wykk.fsf@bsb.me.uk>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<87ee0hyjow.fsf@bsb.me.uk>
<2677cd65-93b9-407b-9966-7815ed205275n@googlegroups.com>
<b7f5d0bd-a13b-4df1-8ccf-8fb29fc3124an@googlegroups.com>
<bd9465aa-4059-4304-8432-e8833ff93e24n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="059b08398b24e05976ef222020b02576";
logging-data="11834"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+u0l1AAjzRUDdsqytDq+ClodSYhTMFUUA="
Cancel-Lock: sha1:vdkQ2IjlTLxSdpfvp953wW4c1nE=
sha1:EX4SByF9xqLV5D4PxyuVwr2MlPc=
X-BSB-Auth: 1.11b2a7adfdc3d386408e.20220525140707BST.87wne9wykk.fsf@bsb.me.uk
 by: Ben - Wed, 25 May 2022 13:07 UTC

fir <profesor.fir@gmail.com> writes:

> środa, 25 maja 2022 o 14:07:22 UTC+2 fir napisał(a):
>> środa, 25 maja 2022 o 13:47:13 UTC+2 fir napisał(a):
>> > środa, 25 maja 2022 o 12:45:50 UTC+2 Ben napisał(a):
>> > > fir <profes...@gmail.com> writes:
>> > >
>> > > > is there some ?
>> > > > people seem tend to use
>> > > >
>> > > > inline float sign (float x) { return (x > 0) - (x < 0); }
>> > > Standard C has copysign. A call to your sign(f) function is equivalent
>> > > to copysign(1, f).
>> > >
>> > > There is also a standard signbit macro that returns 0/1 depending on the
>> > > sign of the argument. These two treat NaNs differently.
>> > >
>> > ok i will see, though it would be better tho have normal functions to not add/multiply
>> > not quite necessary references
>> return -2*signbit(x)+1 ;
>> seem to wrok, though i not tested it except one case
>
> inline float sign2(float x)
> {
> return -2*signbit(x)+1 ;
> }
>
> inline float sign1(float x)
> {
> return (x>0)-(x<0);
> }
>
> for(float f= -333333.33; f< 333333.3; f+=0.33)
> sum += sign2(f);
>
> i tested the efficiency and there is no visible difference here though
> (about 10 ms each, but i run on quite old machine)

gcc, with -O2, generates shorter code for the one you didn't try:

copysignf(1, x)

That does not mean it's faster, but gcc probably has a reason to do what
it does.

Also, in many cases, it's copysign[fl]? that you want, but with
something other than 1 as the first argument.

--
Ben.

Re: eficient float sign routine

<86h75d21np.fsf@linuxsc.com>

  copy mid

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

  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: Wed, 25 May 2022 06:16:10 -0700
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <86h75d21np.fsf@linuxsc.com>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com> <87ee0hyjow.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="9232646268d0bbe52880848ae05fc74d";
logging-data="30560"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19HLXveDMw6AJ5z9vUUzNQ5NAZmfxsyC6U="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:DxwY1fAYCf9LsFAK8MSs3cJcboM=
sha1:8jISSIbTGwX97t2y5HAv1rvijvY=
 by: Tim Rentsch - Wed, 25 May 2022 13:16 UTC

Ben <ben.usenet@bsb.me.uk> writes:

> fir <profesor.fir@gmail.com> writes:
>
>> is there some ?
>> people seem tend to use
>>
>> inline float sign (float x) { return (x > 0) - (x < 0); }
>
> Standard C has copysign. A call to your sign(f) function is equivalent
> to copysign(1, f).

The output doesn't match when the input is 0.

Re: eficient float sign routine

<2a7013a5-a695-442a-a803-bb14cc9f17c3n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:58c6:0:b0:6a3:3037:a5f with SMTP id m189-20020a3758c6000000b006a330370a5fmr19676299qkb.680.1653484752516;
Wed, 25 May 2022 06:19:12 -0700 (PDT)
X-Received: by 2002:a05:620a:44c6:b0:6a5:a3c9:bf6b with SMTP id
y6-20020a05620a44c600b006a5a3c9bf6bmr324273qkp.100.1653484752343; Wed, 25 May
2022 06:19:12 -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: Wed, 25 May 2022 06:19:12 -0700 (PDT)
In-Reply-To: <87wne9wykk.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.170; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.170
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<87ee0hyjow.fsf@bsb.me.uk> <2677cd65-93b9-407b-9966-7815ed205275n@googlegroups.com>
<b7f5d0bd-a13b-4df1-8ccf-8fb29fc3124an@googlegroups.com> <bd9465aa-4059-4304-8432-e8833ff93e24n@googlegroups.com>
<87wne9wykk.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2a7013a5-a695-442a-a803-bb14cc9f17c3n@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 25 May 2022 13:19:12 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: fir - Wed, 25 May 2022 13:19 UTC

środa, 25 maja 2022 o 15:07:22 UTC+2 Ben napisał(a):
> fir <profes...@gmail.com> writes:
>
> > środa, 25 maja 2022 o 14:07:22 UTC+2 fir napisał(a):
> >> środa, 25 maja 2022 o 13:47:13 UTC+2 fir napisał(a):
> >> > środa, 25 maja 2022 o 12:45:50 UTC+2 Ben napisał(a):
> >> > > fir <profes...@gmail.com> writes:
> >> > >
> >> > > > is there some ?
> >> > > > people seem tend to use
> >> > > >
> >> > > > inline float sign (float x) { return (x > 0) - (x < 0); }
> >> > > Standard C has copysign. A call to your sign(f) function is equivalent
> >> > > to copysign(1, f).
> >> > >
> >> > > There is also a standard signbit macro that returns 0/1 depending on the
> >> > > sign of the argument. These two treat NaNs differently.
> >> > >
> >> > ok i will see, though it would be better tho have normal functions to not add/multiply
> >> > not quite necessary references
> >> return -2*signbit(x)+1 ;
> >> seem to wrok, though i not tested it except one case
> >
> > inline float sign2(float x)
> > {
> > return -2*signbit(x)+1 ;
> > }
> >
> > inline float sign1(float x)
> > {
> > return (x>0)-(x<0);
> > }
> >
> > for(float f= -333333.33; f< 333333.3; f+=0.33)
> > sum += sign2(f);
> >
> > i tested the efficiency and there is no visible difference here though
> > (about 10 ms each, but i run on quite old machine)
> gcc, with -O2, generates shorter code for the one you didn't try:
>
> copysignf(1, x)
>
> That does not mean it's faster, but gcc probably has a reason to do what
> it does.
>
> Also, in many cases, it's copysign[fl]? that you want, but with
> something other than 1 as the first argument.
>
thet copysigfn also roughly the same, maybe 5-10% faster but im not sure and have a terible headache today and cant test it too much
initially i tgought this < > version would be much slower (as ifs are slow) but if there is not such big difference the questiob is less important

Re: eficient float sign routine

<b11ea4d0-eab5-4406-b409-d1af691d1c57n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:a9c:b0:6a3:8411:6c78 with SMTP id v28-20020a05620a0a9c00b006a384116c78mr10450366qkg.689.1653488739474;
Wed, 25 May 2022 07:25:39 -0700 (PDT)
X-Received: by 2002:a05:6214:2308:b0:432:e69f:5d71 with SMTP id
gc8-20020a056214230800b00432e69f5d71mr25963690qvb.19.1653488739327; Wed, 25
May 2022 07:25:39 -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: Wed, 25 May 2022 07:25:39 -0700 (PDT)
In-Reply-To: <86h75d21np.fsf@linuxsc.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.198; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.198
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<87ee0hyjow.fsf@bsb.me.uk> <86h75d21np.fsf@linuxsc.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b11ea4d0-eab5-4406-b409-d1af691d1c57n@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 25 May 2022 14:25:39 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2637
 by: fir - Wed, 25 May 2022 14:25 UTC

środa, 25 maja 2022 o 15:16:23 UTC+2 Tim Rentsch napisał(a):
> Ben <ben.u...@bsb.me.uk> writes:
>
> > fir <profes...@gmail.com> writes:
> >
> >> is there some ?
> >> people seem tend to use
> >>
> >> inline float sign (float x) { return (x > 0) - (x < 0); }
> >
> > Standard C has copysign. A call to your sign(f) function is equivalent
> > to copysign(1, f).
> The output doesn't match when the input is 0.

thats right and this extended could be needed
hovever in my case it seem not so much

i need this sign when 'resolving' (adding) some force in a link (join?) agains 2 balls (dots) in 3d
space, say joint assumed distance is 100 when real distance is 110 or 95 then i need to applay force
like -10*10 or +5*5 (square probably best) thus i need a sign

void ResolveLinkForce_(int n, int i, float link_dist)
{ float Mi = dot3d[i].mass;
float dx = dot3d[i].x - dot3d[n].x;
float dy = dot3d[i].y - dot3d[n].y;
float dz = dot3d[i].z - dot3d[n].z;

float d = sqrt(dx*dx + dy*dy + dz*dz);
float dd = (d - link_dist);
float p = -sign(dd)*dd*dd* joint_hardness;

float px = (dx/d)*p;
float py = (dy/d)*p;
float pz = (dz/d)*p;
dot3d[i].vx += px/Mi;
dot3d[i].vy += py/Mi;
dot3d[i].vz += pz/Mi;

}
in case of dd being 0 its all zero so sign dont matter

or maybe i may simplify it at all ?

Re: eficient float sign routine

<afc0f607-77f0-4251-80fb-b9c70eb6cc56n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ad4:596c:0:b0:45d:b08f:830f with SMTP id eq12-20020ad4596c000000b0045db08f830fmr26267779qvb.86.1653490619066;
Wed, 25 May 2022 07:56:59 -0700 (PDT)
X-Received: by 2002:a37:c58:0:b0:6a3:2a71:9904 with SMTP id
85-20020a370c58000000b006a32a719904mr21832120qkm.33.1653490618909; Wed, 25
May 2022 07:56:58 -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: Wed, 25 May 2022 07:56:58 -0700 (PDT)
In-Reply-To: <b11ea4d0-eab5-4406-b409-d1af691d1c57n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.47; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.47
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<87ee0hyjow.fsf@bsb.me.uk> <86h75d21np.fsf@linuxsc.com> <b11ea4d0-eab5-4406-b409-d1af691d1c57n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <afc0f607-77f0-4251-80fb-b9c70eb6cc56n@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 25 May 2022 14:56:59 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4724
 by: fir - Wed, 25 May 2022 14:56 UTC

środa, 25 maja 2022 o 16:25:48 UTC+2 fir napisał(a):
> środa, 25 maja 2022 o 15:16:23 UTC+2 Tim Rentsch napisał(a):
> > Ben <ben.u...@bsb.me.uk> writes:
> >
> > > fir <profes...@gmail.com> writes:
> > >
> > >> is there some ?
> > >> people seem tend to use
> > >>
> > >> inline float sign (float x) { return (x > 0) - (x < 0); }
> > >
> > > Standard C has copysign. A call to your sign(f) function is equivalent
> > > to copysign(1, f).
> > The output doesn't match when the input is 0.
> thats right and this extended could be needed
> hovever in my case it seem not so much
>
> i need this sign when 'resolving' (adding) some force in a link (join?) agains 2 balls (dots) in 3d
> space, say joint assumed distance is 100 when real distance is 110 or 95 then i need to applay force
> like -10*10 or +5*5 (square probably best) thus i need a sign
>
> void ResolveLinkForce_(int n, int i, float link_dist)
> {
> float Mi = dot3d[i].mass;
> float dx = dot3d[i].x - dot3d[n].x;
> float dy = dot3d[i].y - dot3d[n].y;
> float dz = dot3d[i].z - dot3d[n].z;
>
> float d = sqrt(dx*dx + dy*dy + dz*dz);
> float dd = (d - link_dist);
> float p = -sign(dd)*dd*dd* joint_hardness;
>
> float px = (dx/d)*p;
> float py = (dy/d)*p;
> float pz = (dz/d)*p;
> dot3d[i].vx += px/Mi;
> dot3d[i].vy += py/Mi;
> dot3d[i].vz += pz/Mi;
>
> }
> in case of dd being 0 its all zero so sign dont matter
>
> or maybe i may simplify it at all ?

note btw it works curiously well i mean when i get together some things with this dots keeped togehthet by this joints i may fire a dot in it and it will behave realistically (or semi realistically i mean have angular momentum and various complex moves - and this is all done by like 10-20 lines of code (when skipping the non core ones) there are hovever 2 or 3 problems (one is it is square, i eman joints itself are linear but the colisions are square and it slows down, well known problem) (second problem is it disalows fast moves i mean when ball moves the force of collision is square proportional to depth of penetration of ball in ball (at least i use it square, not sure if other are eually good or definietely worse) in fact the colision routine is liek the above except i dont need the sign .. hovever simply if a ball moves to fast it may just teleport thru the obstacles and to have reasonebly fast nice to looking balls but not very fast ones just reasoneble/medicore i need a speed like +100 per frame (at 50 fps) when bal sizes are like typically of 50 or 100 - this makes i need to put like at least 5 or better 10 physical frames instead of one just to make taht speed of movement of objevts down to 10 form 100 just not to tunel through

thisrd problem is sometimes when hit to much all that link build small figure of dots 'explode' - probably
the link distance between dots began to much, the force generated is in turn too much and it explodes, and i dont know what happens but maybe positions goes to nans or infs (the rest of this ball sets continue to work ok, but eventually everything may explode)

doeas maybe someone know is there some simple addition to this link routine above stoping this explosions?

Re: eficient float sign routine

<2d0436b1-6fc5-450a-a133-05ef00afe351n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1a9c:b0:2f3:d873:4acc with SMTP id s28-20020a05622a1a9c00b002f3d8734accmr25248179qtc.424.1653492725660;
Wed, 25 May 2022 08:32:05 -0700 (PDT)
X-Received: by 2002:a05:620a:462a:b0:6a0:28a3:e0f7 with SMTP id
br42-20020a05620a462a00b006a028a3e0f7mr20555087qkb.626.1653492724990; Wed, 25
May 2022 08:32:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!news.uzoreto.com!feeder1.cambriumusenet.nl!feed.tweak.nl!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: Wed, 25 May 2022 08:32:04 -0700 (PDT)
In-Reply-To: <afc0f607-77f0-4251-80fb-b9c70eb6cc56n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.47; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.47
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<87ee0hyjow.fsf@bsb.me.uk> <86h75d21np.fsf@linuxsc.com> <b11ea4d0-eab5-4406-b409-d1af691d1c57n@googlegroups.com>
<afc0f607-77f0-4251-80fb-b9c70eb6cc56n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2d0436b1-6fc5-450a-a133-05ef00afe351n@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 25 May 2022 15:32:05 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: fir - Wed, 25 May 2022 15:32 UTC

środa, 25 maja 2022 o 16:57:07 UTC+2 fir napisał(a):
> środa, 25 maja 2022 o 16:25:48 UTC+2 fir napisał(a):
> > środa, 25 maja 2022 o 15:16:23 UTC+2 Tim Rentsch napisał(a):
> > > Ben <ben.u...@bsb.me.uk> writes:
> > >
> > > > fir <profes...@gmail.com> writes:
> > > >
> > > >> is there some ?
> > > >> people seem tend to use
> > > >>
> > > >> inline float sign (float x) { return (x > 0) - (x < 0); }
> > > >
> > > > Standard C has copysign. A call to your sign(f) function is equivalent
> > > > to copysign(1, f).
> > > The output doesn't match when the input is 0.
> > thats right and this extended could be needed
> > hovever in my case it seem not so much
> >
> > i need this sign when 'resolving' (adding) some force in a link (join?) agains 2 balls (dots) in 3d
> > space, say joint assumed distance is 100 when real distance is 110 or 95 then i need to applay force
> > like -10*10 or +5*5 (square probably best) thus i need a sign
> >
> > void ResolveLinkForce_(int n, int i, float link_dist)
> > {
> > float Mi = dot3d[i].mass;
> > float dx = dot3d[i].x - dot3d[n].x;
> > float dy = dot3d[i].y - dot3d[n].y;
> > float dz = dot3d[i].z - dot3d[n].z;
> >
> > float d = sqrt(dx*dx + dy*dy + dz*dz);
> > float dd = (d - link_dist);
> > float p = -sign(dd)*dd*dd* joint_hardness;
> >
> > float px = (dx/d)*p;
> > float py = (dy/d)*p;
> > float pz = (dz/d)*p;
> > dot3d[i].vx += px/Mi;
> > dot3d[i].vy += py/Mi;
> > dot3d[i].vz += pz/Mi;
> >
> > }
> > in case of dd being 0 its all zero so sign dont matter
> >
> > or maybe i may simplify it at all ?
> note btw it works curiously well i mean when i get together some things with this dots keeped togehthet by this joints i may fire a dot in it and it will behave realistically (or semi realistically i mean have angular momentum and various complex moves - and this is all done by like 10-20 lines of code (when skipping the non core ones) there are hovever 2 or 3 problems (one is it is square, i eman joints itself are linear but the colisions are square and it slows down, well known problem) (second problem is it disalows fast moves i mean when ball moves the force of collision is square proportional to depth of penetration of ball in ball (at least i use it square, not sure if other are eually good or definietely worse) in fact the colision routine is liek the above except i dont need the sign .. hovever simply if a ball moves to fast it may just teleport thru the obstacles and to have reasonebly fast nice to looking balls but not very fast ones just reasoneble/medicore i need a speed like +100 per frame (at 50 fps) when bal sizes are like typically of 50 or 100 - this makes i need to put like at least 5 or better 10 physical frames instead of one just to make taht speed of movement of objevts down to 10 form 100 just not to tunel through
>
> thisrd problem is sometimes when hit to much all that link build small figure of dots 'explode' - probably
> the link distance between dots began to much, the force generated is in turn too much and it explodes, and i dont know what happens but maybe positions goes to nans or infs (the rest of this ball sets continue to work ok, but eventually everything may explode)
>
> doeas maybe someone know is there some simple addition to this link routine above stoping this explosions?

soem may seen a demo of this problem

http://filesharing24.com/d/Oen

this demo dont seem to much good but may ilustrate the problem (in dempo press 5,6,7,8,9, 0
to fire dots into linked dots and some eventually will explode, may also pres f9 tu turn some gravity on and then most of them explode

Re: eficient float sign routine

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!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: Wed, 25 May 2022 16:42:07 +0100
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <87fskxwre8.fsf@bsb.me.uk>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<87ee0hyjow.fsf@bsb.me.uk> <86h75d21np.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="059b08398b24e05976ef222020b02576";
logging-data="21831"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cvV7USutbpDsPMEg5gnQaPkPstMhWkZU="
Cancel-Lock: sha1:Tk3aBnvWYBavxurXW5k0nMcurK0=
sha1:F8yTIBidlmAX1QmUvBrOaKIBwVo=
X-BSB-Auth: 1.a26e560b8032227cdea4.20220525164207BST.87fskxwre8.fsf@bsb.me.uk
 by: Ben - Wed, 25 May 2022 15:42 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

> Ben <ben.usenet@bsb.me.uk> writes:
>
>> fir <profesor.fir@gmail.com> writes:
>>
>>> is there some ?
>>> people seem tend to use
>>>
>>> inline float sign (float x) { return (x > 0) - (x < 0); }
>>
>> Standard C has copysign. A call to your sign(f) function is equivalent
>> to copysign(1, f).
>
> The output doesn't match when the input is 0.

Ah, true.

--
Ben.

Re: eficient float sign routine

<79ceeb71-80b3-4943-a0b5-117307c4ed2cn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:c99:b0:6a3:3c41:2d6 with SMTP id q25-20020a05620a0c9900b006a33c4102d6mr21794719qki.744.1653552155956;
Thu, 26 May 2022 01:02:35 -0700 (PDT)
X-Received: by 2002:ad4:5bc7:0:b0:45b:ab2:6d04 with SMTP id
t7-20020ad45bc7000000b0045b0ab26d04mr28781580qvt.75.1653552155779; Thu, 26
May 2022 01:02:35 -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: Thu, 26 May 2022 01:02:35 -0700 (PDT)
In-Reply-To: <2d0436b1-6fc5-450a-a133-05ef00afe351n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.150; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.150
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<87ee0hyjow.fsf@bsb.me.uk> <86h75d21np.fsf@linuxsc.com> <b11ea4d0-eab5-4406-b409-d1af691d1c57n@googlegroups.com>
<afc0f607-77f0-4251-80fb-b9c70eb6cc56n@googlegroups.com> <2d0436b1-6fc5-450a-a133-05ef00afe351n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <79ceeb71-80b3-4943-a0b5-117307c4ed2cn@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Thu, 26 May 2022 08:02:35 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2238
 by: fir - Thu, 26 May 2022 08:02 UTC

środa, 25 maja 2022 o 17:32:14 UTC+2 fir napisał(a):
>
> this demo dont seem to much good but may ilustrate the problem (in dempo press 5,6,7,8,9, 0
> to fire dots into linked dots and some eventually will explode, may also pres f9 tu turn some gravity on and then most of them explode

this is very simple simulation (seems most simplest that can be) but im usually interested in some
kind of fundaments in such things..still a bit pity processors are so slow and things began to choke
quite early at lieas when using native methods...such simulation is hovever totally adequate to paralisation in turn as you say you got 1 milion dots with pos and v and only need to produce same 1 milion dots with pos and v when order atc totally dont matter

hovever it seems i got no time to toy with that

Re: eficient float sign routine

<873e9c01-cfaf-491e-bdba-90a8c9e2721bn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:4542:b0:6a0:651b:be0b with SMTP id u2-20020a05620a454200b006a0651bbe0bmr24632030qkp.633.1653577197261;
Thu, 26 May 2022 07:59:57 -0700 (PDT)
X-Received: by 2002:ad4:5bc7:0:b0:45b:ab2:6d04 with SMTP id
t7-20020ad45bc7000000b0045b0ab26d04mr30197549qvt.75.1653577197067; Thu, 26
May 2022 07:59:57 -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, 26 May 2022 07:59:56 -0700 (PDT)
In-Reply-To: <2a7013a5-a695-442a-a803-bb14cc9f17c3n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.59; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.59
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<87ee0hyjow.fsf@bsb.me.uk> <2677cd65-93b9-407b-9966-7815ed205275n@googlegroups.com>
<b7f5d0bd-a13b-4df1-8ccf-8fb29fc3124an@googlegroups.com> <bd9465aa-4059-4304-8432-e8833ff93e24n@googlegroups.com>
<87wne9wykk.fsf@bsb.me.uk> <2a7013a5-a695-442a-a803-bb14cc9f17c3n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <873e9c01-cfaf-491e-bdba-90a8c9e2721bn@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Thu, 26 May 2022 14:59:57 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: fir - Thu, 26 May 2022 14:59 UTC

środa, 25 maja 2022 o 15:19:20 UTC+2 fir napisał(a):
> środa, 25 maja 2022 o 15:07:22 UTC+2 Ben napisał(a):
> > fir <profes...@gmail.com> writes:
> >
> > > środa, 25 maja 2022 o 14:07:22 UTC+2 fir napisał(a):
> > >> środa, 25 maja 2022 o 13:47:13 UTC+2 fir napisał(a):
> > >> > środa, 25 maja 2022 o 12:45:50 UTC+2 Ben napisał(a):
> > >> > > fir <profes...@gmail.com> writes:
> > >> > >
> > >> > > > is there some ?
> > >> > > > people seem tend to use
> > >> > > >
> > >> > > > inline float sign (float x) { return (x > 0) - (x < 0); }
> > >> > > Standard C has copysign. A call to your sign(f) function is equivalent
> > >> > > to copysign(1, f).
> > >> > >
> > >> > > There is also a standard signbit macro that returns 0/1 depending on the
> > >> > > sign of the argument. These two treat NaNs differently.
> > >> > >
> > >> > ok i will see, though it would be better tho have normal functions to not add/multiply
> > >> > not quite necessary references
> > >> return -2*signbit(x)+1 ;
> > >> seem to wrok, though i not tested it except one case
> > >
> > > inline float sign2(float x)
> > > {
> > > return -2*signbit(x)+1 ;
> > > }
> > >
> > > inline float sign1(float x)
> > > {
> > > return (x>0)-(x<0);
> > > }
> > >
> > > for(float f= -333333.33; f< 333333.3; f+=0.33)
> > > sum += sign2(f);
> > >
> > > i tested the efficiency and there is no visible difference here though
> > > (about 10 ms each, but i run on quite old machine)
> > gcc, with -O2, generates shorter code for the one you didn't try:
> >
> > copysignf(1, x)
> >
> > That does not mean it's faster, but gcc probably has a reason to do what
> > it does.
> >
> > Also, in many cases, it's copysign[fl]? that you want, but with
> > something other than 1 as the first argument.
> >
> thet copysigfn also roughly the same, maybe 5-10% faster but im not sure and have a terible headache today and cant test it too much
> initially i tgought this < > version would be much slower (as ifs are slow) but if there is not such big difference the questiob is less important

ovaralli i would say 5ns/15 cycles for this it is +=0.33, sum+=sign2(f), check if f<333333.3 is not so bad
but also not a aterribly quick (imo such sole sign could be someting like 3 cycles or so)
but hell knows which it is this if in loop or what

lat time when i checked it it was quite long time ago the ifs was quite slow and it seem to me that
processors would definitively need soem asm opcodes that would do kinda of local ifs without ifs
but being small set of oparatiobs able to be combined to make more complex tasks (like various
arithmetic without real ifs)

meybe in a word where memory bandwith is main limit it doesnt matter so much but still 1-core
strightforward peograming is so nice that any able optimisation would be wery much welcome by me

what could be such ifless operations? i dont know maybe something like this old asm opcodes liek adc using falgs set to do somethink or do not or do soemething other, there those flags works liek ifs

it also eventually could be probably some opcodes that may combine some test and operation in one opcode

Re: eficient float sign routine

<t6rt70$240$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: eficient float sign routine
Date: Fri, 27 May 2022 18:17:18 -0700
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <t6rt70$240$1@dont-email.me>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 28 May 2022 01:17:20 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="691ccf81d4791646bc1e5cd6709627d3";
logging-data="2176"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX189YoeiijI+IO0ry4Y4JTni"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:AU7ESDq6TIfPJheWNAg0gYfh2fE=
In-Reply-To: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
Content-Language: en-US
 by: Andrey Tarasevich - Sat, 28 May 2022 01:17 UTC

On 5/25/2022 3:09 AM, fir wrote:
> is there some ?
> people seem tend to use
>
> inline float sign (float x) { return (x > 0) - (x < 0); }
>
> but im not sure if it is efficient
> afaik float standard says that sign bit is the highest bit ot 32bit
> representation so maybe something based on this?

I presume that your "float standard" is IEEE754, which is not a part of
C standard, but anyway...

The important part of the rationale behind IEEE754 floating-point
representation was the fact that for ordering comparison purposes
floating-point numbers could be type-punned as equally-sized signed
integers and compared as signed integers. This allowed "weak" hardware
(i.e. slow/emulated FP support) to perform plain FP comparisons without
having to invoke anything FP-related at all. (Of course, one had to make
sure one's happy with what happened to such special values as negative
zeroes.)

So, in your case this means that you can type-pun-hack the original FP
problem into an integer problem. Now you can start a topic titled
"eficient int sign routine".

--
Best regards,
Andrey

Re: eficient float sign routine

<rpfkK.67024$5fVf.1346@fx09.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx09.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.9.1
Subject: Re: eficient float sign routine
Content-Language: en-US
Newsgroups: comp.lang.c
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6rt70$240$1@dont-email.me>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <t6rt70$240$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 33
Message-ID: <rpfkK.67024$5fVf.1346@fx09.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Fri, 27 May 2022 22:03:03 -0400
X-Received-Bytes: 2343
 by: Richard Damon - Sat, 28 May 2022 02:03 UTC

On 5/27/22 9:17 PM, Andrey Tarasevich wrote:
> On 5/25/2022 3:09 AM, fir wrote:
>> is there some ?
>> people seem tend to use
>>
>> inline float sign (float x) {  return (x > 0) - (x < 0); }
>>
>> but im not sure if it is efficient
>> afaik float standard says that sign bit is the highest bit ot 32bit
>> representation so maybe something based on this?
>
> I presume that your "float standard" is IEEE754, which is not a part of
> C standard, but anyway...
>
> The important part of the rationale behind IEEE754 floating-point
> representation was the fact that for ordering comparison purposes
> floating-point numbers could be type-punned as equally-sized signed
> integers and compared as signed integers. This allowed "weak" hardware
> (i.e. slow/emulated FP support) to perform plain FP comparisons without
> having to invoke anything FP-related at all. (Of course, one had to make
> sure one's happy with what happened to such special values as negative
> zeroes.)
>
> So, in your case this means that you can type-pun-hack the original FP
> problem into an integer problem. Now you can start a topic titled
> "eficient int sign routine".
>

I thought floating point was stored as signed-magnitude, so you can't
just compare as signed integers, but the comparison was still pretty
quick, you first compare signs, and only if same did you compare
magnatude, but the fields were sorted to make the magnitude comparison
just work.

Re: eficient float sign routine

<t6s32o$350$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: eficient float sign routine
Date: Fri, 27 May 2022 19:57:28 -0700
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <t6s32o$350$1@dont-email.me>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6rt70$240$1@dont-email.me> <rpfkK.67024$5fVf.1346@fx09.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 28 May 2022 02:57:28 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="691ccf81d4791646bc1e5cd6709627d3";
logging-data="3232"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+S8hR0k8ydsOPnVmKoVECJ"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:CGrRl5MgY7Co+epGTE77zsFsZ80=
In-Reply-To: <rpfkK.67024$5fVf.1346@fx09.iad>
Content-Language: en-US
 by: Andrey Tarasevich - Sat, 28 May 2022 02:57 UTC

On 5/27/2022 7:03 PM, Richard Damon wrote:
> On 5/27/22 9:17 PM, Andrey Tarasevich wrote:
>> On 5/25/2022 3:09 AM, fir wrote:
>>> is there some ?
>>> people seem tend to use
>>>
>>> inline float sign (float x) {  return (x > 0) - (x < 0); }
>>>
>>> but im not sure if it is efficient
>>> afaik float standard says that sign bit is the highest bit ot 32bit
>>> representation so maybe something based on this?
>>
>> I presume that your "float standard" is IEEE754, which is not a part
>> of C standard, but anyway...
>>
>> The important part of the rationale behind IEEE754 floating-point
>> representation was the fact that for ordering comparison purposes
>> floating-point numbers could be type-punned as equally-sized signed
>> integers and compared as signed integers. This allowed "weak" hardware
>> (i.e. slow/emulated FP support) to perform plain FP comparisons
>> without having to invoke anything FP-related at all. (Of course, one
>> had to make sure one's happy with what happened to such special values
>> as negative zeroes.)
>>
>> So, in your case this means that you can type-pun-hack the original FP
>> problem into an integer problem. Now you can start a topic titled
>> "eficient int sign routine".
>>
>
> I thought floating point was stored as signed-magnitude, so you can't
> just compare as signed integers, but the comparison was still pretty
> quick, you first compare signs, and only if same did you compare
> magnatude, but the fields were sorted to make the magnitude comparison
> just work.

You are right. They have to be type-punned as signed magnitude
specifically in order to be compared as integers.

--
Best regards,
Andrey

Re: eficient float sign routine

<9d5b3a38-bd37-44ef-9c83-020fc0b0e694n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:f24:b0:464:3736:487 with SMTP id iw4-20020a0562140f2400b0046437360487mr2193708qvb.88.1653714402325;
Fri, 27 May 2022 22:06:42 -0700 (PDT)
X-Received: by 2002:ad4:5967:0:b0:462:10a3:cbf6 with SMTP id
eq7-20020ad45967000000b0046210a3cbf6mr32404746qvb.127.1653714402093; Fri, 27
May 2022 22:06:42 -0700 (PDT)
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!news.mixmin.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: Fri, 27 May 2022 22:06:41 -0700 (PDT)
In-Reply-To: <t6rt70$240$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.70; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.70
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com> <t6rt70$240$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9d5b3a38-bd37-44ef-9c83-020fc0b0e694n@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Sat, 28 May 2022 05:06:42 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: fir - Sat, 28 May 2022 05:06 UTC

sobota, 28 maja 2022 o 03:17:34 UTC+2 Andrey Tarasevich napisał(a):
> On 5/25/2022 3:09 AM, fir wrote:
> > is there some ?
> > people seem tend to use
> >
> > inline float sign (float x) { return (x > 0) - (x < 0); }
> >
> > but im not sure if it is efficient
> > afaik float standard says that sign bit is the highest bit ot 32bit
> > representation so maybe something based on this?
> I presume that your "float standard" is IEEE754, which is not a part of
> C standard, but anyway...
>
> The important part of the rationale behind IEEE754 floating-point
> representation was the fact that for ordering comparison purposes
> floating-point numbers could be type-punned as equally-sized signed
> integers and compared as signed integers. This allowed "weak" hardware
> (i.e. slow/emulated FP support) to perform plain FP comparisons without
> having to invoke anything FP-related at all. (Of course, one had to make
> sure one's happy with what happened to such special values as negative
> zeroes.)
>
> So, in your case this means that you can type-pun-hack the original FP
> problem into an integer problem. Now you can start a topic titled
> "eficient int sign routine".
>

people shpul;d trop they thinking that c is only what is defined in standard,
c is what people use not of what only is defined by 'standard'

i think much can be done by using float binary representation which in turn
is not hard, kinda weird they dont used 24 bits on lower 'integer' part (it would make round 3 bytes
then) im not shure also if that shift of 'dot' part is done right

1 is for example 00111111100000000000000000000000
2 is 01000000000000000000000000000000
4 is 01000000100000000000000000000000
(according to https://www.h-schmidt.net/FloatConverter/IEEE754.html )

as powers of 2 are always in fo rm 100.......0 and the first 1 is not stored shouldnt 4
be [2][0] (when first is exponent part and second are integer bits) ?
i think also this sign moved to highest bite is not necessary best idea it
could be better just have 3 bytes for integer (including its sign) and 1 byte for 'exponent'

hovever in fact, this sign not necesarrely need to be in this integer part as the highest bit is already skipped to simple copying will not recreate the oryginal integer

hovever i think probbaly this float should be done like this that 3 bytes would be identical as
normal 3 bytes of integer so zero should be 00000000 00000000 0000000 and 1 shopuld be 00000000 00000000 00000001 minus one should be 11111111 11111111 11111111 as to exponent part i dont know but probably should denote zeros/ones added lefot or right or something

this problem needs to be rethinked though,m though my brain like lost interestmen in that things which used to vitally interest me back days, its curious

Re: eficient float sign routine

<0dd29ff5-b525-4d34-aa32-a3b0e41b71c0n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:46a1:b0:6a0:465e:ccca with SMTP id bq33-20020a05620a46a100b006a0465ecccamr30363636qkb.631.1653716946616;
Fri, 27 May 2022 22:49:06 -0700 (PDT)
X-Received: by 2002:a05:620a:1a22:b0:6a5:dac3:7fb1 with SMTP id
bk34-20020a05620a1a2200b006a5dac37fb1mr4457214qkb.377.1653716946393; Fri, 27
May 2022 22:49:06 -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: Fri, 27 May 2022 22:49:06 -0700 (PDT)
In-Reply-To: <9d5b3a38-bd37-44ef-9c83-020fc0b0e694n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.100; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.100
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6rt70$240$1@dont-email.me> <9d5b3a38-bd37-44ef-9c83-020fc0b0e694n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0dd29ff5-b525-4d34-aa32-a3b0e41b71c0n@googlegroups.com>
Subject: Re: eficient float sign routine
From: profesor...@gmail.com (fir)
Injection-Date: Sat, 28 May 2022 05:49:06 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: fir - Sat, 28 May 2022 05:49 UTC

sobota, 28 maja 2022 o 07:06:49 UTC+2 fir napisał(a):
> sobota, 28 maja 2022 o 03:17:34 UTC+2 Andrey Tarasevich napisał(a):
> > On 5/25/2022 3:09 AM, fir wrote:
> > > is there some ?
> > > people seem tend to use
> > >
> > > inline float sign (float x) { return (x > 0) - (x < 0); }
> > >
> > > but im not sure if it is efficient
> > > afaik float standard says that sign bit is the highest bit ot 32bit
> > > representation so maybe something based on this?
> > I presume that your "float standard" is IEEE754, which is not a part of
> > C standard, but anyway...
> >
> > The important part of the rationale behind IEEE754 floating-point
> > representation was the fact that for ordering comparison purposes
> > floating-point numbers could be type-punned as equally-sized signed
> > integers and compared as signed integers. This allowed "weak" hardware
> > (i.e. slow/emulated FP support) to perform plain FP comparisons without
> > having to invoke anything FP-related at all. (Of course, one had to make
> > sure one's happy with what happened to such special values as negative
> > zeroes.)
> >
> > So, in your case this means that you can type-pun-hack the original FP
> > problem into an integer problem. Now you can start a topic titled
> > "eficient int sign routine".
> >
> people shpul;d trop they thinking that c is only what is defined in standard,
> c is what people use not of what only is defined by 'standard'
>
> i think much can be done by using float binary representation which in turn
> is not hard, kinda weird they dont used 24 bits on lower 'integer' part (it would make round 3 bytes
> then) im not shure also if that shift of 'dot' part is done right
>
> 1 is for example 00111111100000000000000000000000
> 2 is 01000000000000000000000000000000
> 4 is 01000000100000000000000000000000
> (according to https://www.h-schmidt.net/FloatConverter/IEEE754.html )
>
> as powers of 2 are always in fo rm 100.......0 and the first 1 is not stored shouldnt 4
> be [2][0] (when first is exponent part and second are integer bits) ?
> i think also this sign moved to highest bite is not necessary best idea it
> could be better just have 3 bytes for integer (including its sign) and 1 byte for 'exponent'
>
> hovever in fact, this sign not necesarrely need to be in this integer part as the highest bit is already skipped to simple copying will not recreate the oryginal integer
>
> hovever i think probbaly this float should be done like this that 3 bytes would be identical as
> normal 3 bytes of integer so zero should be 00000000 00000000 0000000 and 1 shopuld be 00000000 00000000 00000001 minus one should be 11111111 11111111 11111111 as to exponent part i dont know but probably should denote zeros/ones added lefot or right or something
>
> this problem needs to be rethinked though,m though my brain like lost interestmen in that things which used to vitally interest me back days, its curious

maybe it should be like that 3 bytes are exact integer, teh exponened should say how many xxxx
add on right ond on left like integerxxxxxxxx. and .xxxxxxinteger though im not sure/probably in case
on negative integer xxxx should be not zeros but ones, im not sure though (and not sure if i like U2 at all)

Re: eficient float sign routine

<t6tmt6$d76$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: eficient float sign routine
Date: Sat, 28 May 2022 19:42:09 +0200
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <t6tmt6$d76$1@dont-email.me>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 28 May 2022 17:41:58 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4d8e423a835c113411d5cb933c52d386";
logging-data="13542"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/B58DcioXrgPmbAdzgn6CHLl/5Z3lMoQ8="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:1QfMJ/i5WE5DAk6afTA+DJZDNjk=
In-Reply-To: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Sat, 28 May 2022 17:42 UTC

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 );

Gives:

"??$giveSign@M@@YAHM@Z":
movd eax, xmm0
ret

"??$giveSign@N@@YA_JN@Z":
movq rax, xmm0
ret

Re: eficient float sign routine

<t6tnb4$fe1$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: eficient float sign routine
Date: Sat, 28 May 2022 19:49:35 +0200
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <t6tnb4$fe1$1@dont-email.me>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6tmt6$d76$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 28 May 2022 17:49:24 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4d8e423a835c113411d5cb933c52d386";
logging-data="15809"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18JvtC7yTSWJjY8SiDNTJJwwNT3ll4q3Oo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:4EWYtSkbUtPah5Am1hMmdhgfYr8=
In-Reply-To: <t6tmt6$d76$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Sat, 28 May 2022 17:49 UTC

Sorry, litle mistake:

#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
int giveSign( FpType value )
{ using namespace std;
conditional_t<same_as<FpType, float>, int32_t, int64_t> iValue;
memcpy( &iValue, &value, sizeof value );
return (iValue > 0) - (iValue < 0);
}

template
int giveSign( float );

template
int giveSign( double );

Gives:

"??$giveSign@M@@YAHM@Z":
movd eax, xmm0
xor ecx, ecx
test eax, eax
setg cl
sar eax, 31
add eax, ecx
ret

"??$giveSign@N@@YAHN@Z":
movq rax, xmm0
xor ecx, ecx
test rax, rax
setg cl
sar rax, 63
add eax, ecx

Compiler: clang-cl 13.

Re: eficient float sign routine

<wXukK.37418$J0r9.3724@fx11.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx11.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: eficient float sign routine
Newsgroups: comp.lang.c
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com> <t6tmt6$d76$1@dont-email.me>
Lines: 39
Message-ID: <wXukK.37418$J0r9.3724@fx11.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sat, 28 May 2022 19:43:24 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sat, 28 May 2022 19:43:24 GMT
X-Received-Bytes: 1483
 by: Scott Lurndal - Sat, 28 May 2022 19:43 UTC

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.

#include <math.h>

int main()
{ float_t number = -1.235;

sign = signbit(number);
return sign;
}

Re: eficient float sign routine

<t6u21o$pje$1@gioia.aioe.org>

  copy mid

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

  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: Sat, 28 May 2022 22:52:08 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t6u21o$pje$1@gioia.aioe.org>
References: <a2c40762-4e51-41e0-9f31-0a780e5370bcn@googlegroups.com>
<t6tmt6$d76$1@dont-email.me> <wXukK.37418$J0r9.3724@fx11.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="26222"; 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
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Manfred - Sat, 28 May 2022 20:52 UTC

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.

>
> #include <math.h>
>
> int main()
> {
> float_t number = -1.235;
>
> // sign = signbit(number);

int sign = signbit(number);

> return sign;
> }

Re: eficient float sign routine

<877d65w6jp.fsf@bsb.me.uk>

  copy mid

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

  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 01:01:30 +0100
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <877d65w6jp.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>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="186fd15395331ee5fbcd6d71035d1d29";
logging-data="31163"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+J3m02TdK+DUD9qEi2VBGLJkTrmClm40o="
Cancel-Lock: sha1:0xBgh4hW8WRl4UY/904PS0GSqf0=
sha1:17ijzAqzl3pqEUC9kcU0ASe3azw=
X-BSB-Auth: 1.b1062cea4c15503f329b.20220529010130BST.877d65w6jp.fsf@bsb.me.uk
 by: Ben - Sun, 29 May 2022 00:01 UTC

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.

>> #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);

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.

>> return sign;
>> }

--
Ben.

Pages:123
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor