Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #71022 > unrolled thread
| Started by | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| First post | 2015-09-21 20:17 +0200 |
| Last post | 2015-09-22 11:23 +0200 |
| Articles | 20 on this page of 145 — 21 participants |
Back to article view | Back to comp.lang.c
How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-21 20:17 +0200
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-21 20:43 +0200
Re: How to write this sign function in Delphi. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-21 19:51 +0100
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-21 23:26 +0200
Re: How to write this sign function in Delphi. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-21 22:47 +0100
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-22 16:29 +0200
Re: How to write this sign function in Delphi. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-22 16:11 +0100
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-23 11:18 +0200
Re: How to write this sign function in Delphi. David Brown <david.brown@hesbynett.no> - 2015-09-23 13:01 +0200
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-21 20:53 +0200
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-21 20:54 +0200
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-21 20:58 +0200
Re: How to write this sign function in Delphi. M Philbrook <jamie_ka1lpa@charter.net> - 2015-09-21 18:15 -0400
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-09-21 15:21 -0700
Re: How to write this sign function in Delphi. Robert Wessel <robertwessel2@yahoo.com> - 2015-09-21 17:51 -0500
Re: How to write this sign function in Delphi. James Kuyper <jameskuyper@verizon.net> - 2015-09-21 19:15 -0400
Re: How to write this sign function in Delphi. Robert Wessel <robertwessel2@yahoo.com> - 2015-09-21 23:59 -0500
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-09-22 09:22 -0700
Re: How to write this sign function in Delphi. Keith Thompson <kst-u@mib.org> - 2015-09-22 10:32 -0700
Re: How to write this sign function in Delphi. jt@toerring.de (Jens Thoms Toerring) - 2015-09-22 18:17 +0000
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-09-22 12:25 -0700
Re: How to write this sign function in Delphi. jt@toerring.de (Jens Thoms Toerring) - 2015-09-22 22:33 +0000
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-09-22 15:52 -0700
Re: How to write this sign function in Delphi. raltbos@xs4all.nl (Richard Bos) - 2015-09-22 23:09 +0000
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-09-23 09:07 -0700
Re: How to write this sign function in Delphi. Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-09-23 16:55 +0000
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-09-23 10:46 -0700
Re: How to write this sign function in Delphi. jt@toerring.de (Jens Thoms Toerring) - 2015-09-23 23:18 +0000
Re: How to write this sign function in Delphi. James Kuyper <jameskuyper@verizon.net> - 2015-09-23 22:29 -0400
Re: How to write this sign function in Delphi. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-24 11:09 +0100
Re: How to write this sign function in Delphi. Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-27 18:23 -0700
Re: How to write this sign function in Delphi. glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-09-28 05:20 +0000
Re: How to write this sign function in Delphi. Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-27 23:23 -0700
Re: How to write this sign function in Delphi. Richard Heathfield <rjh@cpax.org.uk> - 2015-09-28 09:03 +0100
Re: How to write this sign function in Delphi. Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-28 01:24 -0700
Re: How to write this sign function in Delphi. Richard Heathfield <rjh@cpax.org.uk> - 2015-09-28 09:32 +0100
Re: How to write this sign function in Delphi. Bartc <bc@freeuk.com> - 2015-09-28 10:22 +0100
Re: How to write this sign function in Delphi. Richard Heathfield <rjh@cpax.org.uk> - 2015-09-28 11:35 +0100
Re: How to write this sign function in Delphi. Keith Thompson <kst-u@mib.org> - 2015-09-28 10:33 -0700
Re: How to write this sign function in Delphi. Richard Heathfield <rjh@cpax.org.uk> - 2015-09-28 18:59 +0100
Re: How to write this sign function in Delphi. Rosario19 <Ros@invalid.invalid> - 2015-09-28 20:09 +0200
Re: How to write this sign function in Delphi. Robert Wessel <robertwessel2@yahoo.com> - 2015-09-28 13:39 -0500
Re: How to write this sign function in Delphi. Richard Heathfield <rjh@cpax.org.uk> - 2015-09-28 20:04 +0100
Re: How to write this sign function in Delphi. Robert Wessel <robertwessel2@yahoo.com> - 2015-09-28 16:43 -0500
Re: How to write this sign function in Delphi. Martin Shobe <martin.shobe@yahoo.com> - 2015-09-28 18:55 -0500
Re: How to write this sign function in Delphi. Robert Wessel <robertwessel2@yahoo.com> - 2015-09-28 19:31 -0500
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-09-28 12:16 -0700
Re: How to write this sign function in Delphi. Keith Thompson <kst-u@mib.org> - 2015-09-28 14:31 -0700
Re: How to write this sign function in Delphi. Robert Wessel <robertwessel2@yahoo.com> - 2015-09-28 16:47 -0500
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-09-29 11:54 -0700
Re: How to write this sign function in Delphi. Robert Wessel <robertwessel2@yahoo.com> - 2015-10-01 00:36 -0500
Re: How to write this sign function in Delphi. raltbos@xs4all.nl (Richard Bos) - 2015-10-02 10:53 +0000
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-02 09:48 -0700
Re: How to write this sign function in Delphi. Robert Wessel <robertwessel2@yahoo.com> - 2015-10-03 11:27 -0500
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-03 12:32 -0700
Re: How to write this sign function in Delphi. Robert Wessel <robertwessel2@yahoo.com> - 2015-10-03 11:26 -0500
Re: How to write this sign function in Delphi. Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-04 16:46 -0700
Re: How to write this sign function in Delphi. Keith Thompson <kst-u@mib.org> - 2015-09-28 14:23 -0700
Re: How to write this sign function in Delphi. Robert Wessel <robertwessel2@yahoo.com> - 2015-09-28 16:52 -0500
Re: How to write this sign function in Delphi. Tim Rentsch <txr@alumni.caltech.edu> - 2015-09-30 01:39 -0700
Re: How to write this sign function in Delphi. Keith Thompson <kst-u@mib.org> - 2015-09-30 12:37 -0700
Re: How to write this sign function in Delphi. glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-09-30 21:28 +0000
Re: How to write this sign function in Delphi. James Kuyper <jameskuyper@verizon.net> - 2015-09-30 17:54 -0400
Re: How to write this sign function in Delphi. glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-10-01 03:59 +0000
Re: How to write this sign function in Delphi. James Kuyper <jameskuyper@verizon.net> - 2015-10-01 01:42 -0400
Re: How to write this sign function in Delphi. Keith Thompson <kst-u@mib.org> - 2015-09-30 16:20 -0700
Re: How to write this sign function in Delphi. Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-04 16:39 -0700
Re: How to write this sign function in Delphi. glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-09-28 23:23 +0000
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-09-29 09:35 -0700
Re: How to write this sign function in Delphi. raltbos@xs4all.nl (Richard Bos) - 2015-10-02 11:06 +0000
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-02 09:23 -0700
Re: How to write this sign function in Delphi. Martin Shobe <martin.shobe@yahoo.com> - 2015-10-02 12:07 -0500
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-02 10:47 -0700
Re: How to write this sign function in Delphi. Keith Thompson <kst-u@mib.org> - 2015-10-02 17:48 -0700
Re: How to write this sign function in Delphi. Richard Heathfield <rjh@cpax.org.uk> - 2015-10-03 16:46 +0100
Re: How to write this sign function in Delphi. Martin Shobe <martin.shobe@yahoo.com> - 2015-10-05 10:41 -0500
Re: How to write this sign function in Delphi. James Kuyper <jameskuyper@verizon.net> - 2015-09-28 15:31 -0400
Re: How to write this sign function in Delphi. Robert Wessel <robertwessel2@yahoo.com> - 2015-09-28 16:40 -0500
Re: How to write this sign function in Delphi. James Kuyper <jameskuyper@verizon.net> - 2015-09-28 18:17 -0400
Re: How to write this sign function in Delphi. Tim Rentsch <txr@alumni.caltech.edu> - 2015-09-30 02:49 -0700
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-09-30 06:27 -0700
Re: How to write this sign function in Delphi. Tim Rentsch <txr@alumni.caltech.edu> - 2015-09-29 10:43 -0700
Re: How to write this sign function in Delphi. glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-09-28 22:51 +0000
Re: How to write this sign function in Delphi. Tim Rentsch <txr@alumni.caltech.edu> - 2015-09-30 02:11 -0700
Re: How to write this sign function in Delphi. glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-09-28 22:48 +0000
Re: How to write this sign function in Delphi. Robert Wessel <robertwessel2@yahoo.com> - 2015-09-28 22:03 -0500
Re: How to write this sign function in Delphi. Tim Rentsch <txr@alumni.caltech.edu> - 2015-09-30 01:13 -0700
Re: How to write this sign function in Delphi. Bartc <bc@freeuk.com> - 2015-09-30 17:06 +0100
Re: How to write this sign function in Delphi. Richard Heathfield <rjh@cpax.org.uk> - 2015-09-30 17:26 +0100
Re: How to write this sign function in Delphi. Keith Thompson <kst-u@mib.org> - 2015-09-30 13:04 -0700
Re: How to write this sign function in Delphi. glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-09-28 09:12 +0000
Re: How to write this sign function in Delphi. David Brown <david.brown@hesbynett.no> - 2015-09-28 12:28 +0200
Re: How to write this sign function in Delphi. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-28 20:44 +0100
Re: How to write this sign function in Delphi. Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-01 01:39 -0700
Re: How to write this sign function in Delphi. Keith Thompson <kst-u@mib.org> - 2015-10-01 08:55 -0700
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-01 09:02 -0700
Re: How to write this sign function in Delphi. Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-01 14:55 -0700
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-01 16:48 -0700
Re: How to write this sign function in Delphi. raltbos@xs4all.nl (Richard Bos) - 2015-10-02 11:46 +0000
Re: How to write this sign function in Delphi. Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-06 00:15 -0700
Re: How to write this sign function in Delphi. Les Cargill <lcargill99@comcast.com> - 2015-10-06 02:43 -0500
Re: How to write this sign function in Delphi. David Brown <david.brown@hesbynett.no> - 2015-10-06 10:13 +0200
Re: How to write this sign function in Delphi. Les Cargill <lcargill99@comcast.com> - 2015-10-06 19:14 -0500
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-06 21:36 -0700
Re: How to write this sign function in Delphi. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-06 09:25 +0100
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-06 09:28 -0700
Re: How to write this sign function in Delphi. Keith Thompson <kst-u@mib.org> - 2015-10-06 13:11 -0700
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-06 13:56 -0700
Re: How to write this sign function in Delphi. glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-10-07 00:25 +0000
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-06 09:44 -0700
Re: How to write this sign function in Delphi. Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-06 10:08 -0700
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-06 12:00 -0700
Re: How to write this sign function in Delphi. Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-07 01:58 -0700
Re: How to write this sign function in Delphi. Richard Heathfield <rjh@cpax.org.uk> - 2015-10-07 10:12 +0100
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-08 00:40 -0700
Re: How to write this sign function in Delphi. Philip Lantz <prl@canterey.us> - 2015-10-03 12:29 -0700
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-03 13:20 -0700
Re: How to write this sign function in Delphi. Philip Lantz <prl@canterey.us> - 2015-10-03 12:33 -0700
Re: How to write this sign function in Delphi. James Kuyper <jameskuyper@verizon.net> - 2015-10-03 17:02 -0400
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-03 15:04 -0700
Re: How to write this sign function in Delphi. glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-10-04 05:12 +0000
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-04 12:58 -0700
Re: How to write this sign function in Delphi. Philip Lantz <prl@canterey.us> - 2015-10-03 12:37 -0700
Re: How to write this sign function in Delphi. James Kuyper <jameskuyper@verizon.net> - 2015-10-03 16:21 -0400
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-03 16:05 -0700
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-10-03 14:02 -0700
Re: How to write this sign function in Delphi. supercat@casperkitty.com - 2015-09-24 09:39 -0700
Re: How to write this sign function in Delphi. raltbos@xs4all.nl (Richard Bos) - 2015-09-27 16:26 +0000
Re: How to write this sign function in Delphi. M Philbrook <jamie_ka1lpa@charter.net> - 2015-09-21 22:06 -0400
Re: How to write this sign function in Delphi. James Kuyper <jameskuyper@verizon.net> - 2015-09-22 10:17 -0400
Re: How to write this sign function in Delphi. M Philbrook <jamie_ka1lpa@charter.net> - 2015-09-22 19:48 -0400
Re: How to write this sign function in Delphi. Noob <root@127.0.0.1> - 2015-09-23 13:15 +0200
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-21 21:25 +0200
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-21 21:54 +0200
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-21 22:02 +0200
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-21 21:50 +0200
Re: How to write this sign function in Delphi. M Philbrook <jamie_ka1lpa@charter.net> - 2015-09-21 18:08 -0400
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-22 08:31 +0200
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-22 10:18 +0200
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-22 10:50 +0200
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-22 11:00 +0200
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-22 11:07 +0200
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-22 11:20 +0200
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-22 11:15 +0200
Re: How to write this sign function in Delphi. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-09-22 11:23 +0200
Page 1 of 8 [1] 2 3 4 5 6 7 8 Next page →
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-09-21 20:17 +0200 |
| Subject | How to write this sign function in Delphi. |
| Message-ID | <1315e$5600499f$d47876e2$34602@news.ziggo.nl> |
Hello,
Something strange going on with this C code, in Visual Studio 2010 the
result of Sign will be either -1, 0 or 1.
int Sign( int x )
{
return ((!!x) | (x >> 31));
}
int _tmain(int argc, _TCHAR* argv[])
{
printf("%d \n", Sign(-100));
printf("%d \n", Sign(0));
printf("%d \n", Sign(100));
return 0;
}
When trying to port this to Delphi it gives different results.
function IntegerSign( Para : integer ) : integer;
begin
result := ((not(not Para)) or (Para shr 31));
end;
function IntegerSign( Para : integer ) : integer;
begin
result := (Para xor (not Para)) or (Para shr 31));
end;
function IntegerSign( Para : integer ) : integer;
begin
result := (Para xor (-Para)) or (Para shr 31));
end;
Is there a way to write this C function in Delphi so it also returns -1, 0
and 1 in Delphi ???
Bye,
Skybuck.
[toc] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-09-21 20:43 +0200 |
| Message-ID | <883e7$56004fdb$d47876e2$40959@news.ziggo.nl> |
| In reply to | #71022 |
Ok, I've heard situations like this before... I think one of the problems might be that C uses SAR instead of SHR. Using SAR means "negativity" is kept when shifting. So the negativity seems to be lost in Delphi. the SAR 31 is a trick to isolate negativity versus positivity. in Delphi/SHR this is lost and only zero or positivity is kept. What remains unclear to me is the !! operator. Is this a double not operator ? Or something else ? ;) At least now that I understand more of the problem I may be able to come up with a solution in Delphi. But first I gotta go eat ! ;) =D To be continued... Bye, Skybuck. P.S.: For the first time I am frying my supermarket lasagne in the oven/convection mode instead of microwave mode. I have done it only once before... but with a different kind of lasagne lol.. I hope the black bucket is ok for oven I think so... manual said nothing about having to replace it in a special thing... hmmm..
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-09-21 19:51 +0100 |
| Message-ID | <87d1xba9nd.fsf@bsb.me.uk> |
| In reply to | #71022 |
[Newsgroups trimmed because I'm commenting only on the C part.]
"Skybuck Flying" <skybuck2000@hotmail.com> writes:
> Something strange going on with this C code, in Visual Studio 2010 the
> result of Sign will be either -1, 0 or 1.
>
> int Sign( int x )
> {
> return ((!!x) | (x >> 31));
> }
Shifting a negative value right is implementation defined so this is not
a portable way to write it.
return (x > 0) - (x < 0);
is portable and, to my mind, clearer. Also, unlike the original, it
will probably translate simply to almost any other language.
<snip>
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-09-21 23:26 +0200 |
| Message-ID | <57204$560075e9$d47876e2$57079@news.ziggo.nl> |
| In reply to | #71026 |
Hi, I just figured this part out more or less... It's nice to see where this solution seems to be coming from. Pretty cool: return (x > 0) - (x < 0); However I think the challenge here is to try and write it in a branchless way. Seeing this idea it's probably possibly to replace x > 0 and x < 0 with some branchless versions ;) Bye, Skybuck.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-09-21 22:47 +0100 |
| Message-ID | <877fnja1h6.fsf@bsb.me.uk> |
| In reply to | #71041 |
"Skybuck Flying" <skybuck2000@hotmail.com> writes: <snip> > return (x > 0) - (x < 0); > > However I think the challenge here is to try and write it in a > branchless way. This is branchless (in the conventional sense of the word). You might mean something else. <snip> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-09-22 16:29 +0200 |
| Message-ID | <1cbb9$560165dc$d47876e2$55044@news.ziggo.nl> |
| In reply to | #71042 |
> return (x > 0) - (x < 0); > > However I think the challenge here is to try and write it in a > branchless way. " This is branchless (in the conventional sense of the word). You might mean something else. " Don't think so... compiler is only a tool to help with generating assembler instructions. If you want to know what's really going on, examine the assembler instructions. Bye, Skybuck.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-09-22 16:11 +0100 |
| Message-ID | <877fnih4k8.fsf@bsb.me.uk> |
| In reply to | #71095 |
"Skybuck Flying" <skybuck2000@hotmail.com> writes: It is considered good style to generate (and preserve) relevant attribution lines. >> return (x > 0) - (x < 0); >> >> However I think the challenge here is to try and write it in a >> branchless way. > > " > This is branchless (in the conventional sense of the word). You might > mean something else. > " > > Don't think so... compiler is only a tool to help with generating > assembler instructions. That's a view I don't happen to share, but it's not important here. > If you want to know what's really going on, examine the assembler > instructions. I did -- no branches. If your compiler generated a branch for that code you might want to consider changing it. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-09-23 11:18 +0200 |
| Message-ID | <e6d51$56026e4c$d47876e2$15364@news.ziggo.nl> |
| In reply to | #71098 |
" It is considered good style to generate (and preserve) relevant attribution lines. " Those attribution lines are totally mess-up-confused-up by newsreaders/postings/quations and will only confuse people. If you want attribution then do as me, write at the bottom: Bye, <your name> =D >> return (x > 0) - (x < 0); >> >> However I think the challenge here is to try and write it in a >> branchless way. > > " > This is branchless (in the conventional sense of the word). You might > mean something else. > " > > Don't think so... compiler is only a tool to help with generating > assembler instructions. That's a view I don't happen to share, but it's not important here. > If you want to know what's really going on, examine the assembler > instructions. " I did -- no branches. If your compiler generated a branch for that code you might want to consider changing it. " Fair enough, though the instructions are "rumored" to be slow =D " return (x > 0) - (x < 0); 0011353E xor eax,eax 00113540 cmp dword ptr [x],0 00113544 setg al 00113547 xor ecx,ecx 00113549 cmp dword ptr [x],0 0011354D setl cl 00113550 sub eax,ecx " Not sure how fast the !! version would be ! ;) Bye, Skybuck
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2015-09-23 13:01 +0200 |
| Message-ID | <mtu0ml$19q$1@dont-email.me> |
| In reply to | #71132 |
On 23/09/15 11:18, Skybuck Flying wrote: > " > It is considered good style to generate (and preserve) relevant > attribution lines. > " > > Those attribution lines are totally mess-up-confused-up by > newsreaders/postings/quations and will only confuse people. > > If you want attribution then do as me, write at the bottom: > > Bye, > <your name> > > =D > Almost everyone else manages to get quotations and attributions right - because there is a solid standard for it, and most newsreaders follow it. If your newsreader has trouble following those standards, get a better newsreader (Thunderbird is the obvious choice for many people, unless you have particular reason for choosing something else).
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-09-21 20:53 +0200 |
| Message-ID | <e0296$5600521a$d47876e2$43650@news.ziggo.nl> |
| In reply to | #71022 |
Interesting... amazingly enough... the black plastic didn't melt. I thought it wouldn't cause in microwave mode the heat can also be pretty intense... So oven should survive it too... I guess it's some new kind of plastic ! ;) I have seen some of this kind of plastic bending though ! ;) Bye, Skybuck.
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-09-21 20:54 +0200 |
| Message-ID | <d1ffd$5600525b$d47876e2$43950@news.ziggo.nl> |
| In reply to | #71022 |
Well that was a total fail lol.. It wasnt' heated properly... Maybe I should have put it on a rack. Oh well.. I ll just stick with micro over mode for now ! ;) Bye, Skybuck :)
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-09-21 20:58 +0200 |
| Message-ID | <f3842$5600536b$d47876e2$45003@news.ziggo.nl> |
| In reply to | #71022 |
! in C is supposed to be logical not. Not exactly sure what is ment with that... but to me it would seem this converts integers to boolean. So this could be some kind of integer to boolean conversion operator. Perhaps a typecast to boolean might help for Delphi. Anyway I also base this on inspecting the assembly a little bit... there was a cmp in it... which probably sets some flags... and then some kind of set instruction was executed. Just for the kick of it here it is: return ((!!x) | (x >> 31)); 010A13AE xor eax,eax 010A13B0 cmp dword ptr [x],0 010A13B4 setne al 010A13B7 mov ecx,dword ptr [x] 010A13BA sar ecx,1Fh 010A13BD or eax,ecx Bye, Skybuck.
[toc] | [prev] | [next] | [standalone]
| From | M Philbrook <jamie_ka1lpa@charter.net> |
|---|---|
| Date | 2015-09-21 18:15 -0400 |
| Message-ID | <MPG.306a4b87db8f8e87989cf8@news.eternal-september.org> |
| In reply to | #71030 |
In article <f3842$5600536b$d47876e2$45003@news.ziggo.nl>, skybuck2000 @hotmail.com says... > > ! in C is supposed to be logical not. > > Not exactly sure what is ment with that... but to me it would seem this > converts integers to boolean. > > So this could be some kind of integer to boolean conversion operator. > > Perhaps a typecast to boolean might help for Delphi. > > Anyway I also base this on inspecting the assembly a little bit... there was > a cmp in it... which probably sets some flags... > > and then some kind of set instruction was executed. > > Just for the kick of it here it is: > > > return ((!!x) | (x >> 31)); > > 010A13AE xor eax,eax > > 010A13B0 cmp dword ptr [x],0 > > 010A13B4 setne al > > 010A13B7 mov ecx,dword ptr [x] > > 010A13BA sar ecx,1Fh > > 010A13BD or eax,ecx > > > > Bye, > > Skybuck. I would like to know why you are using double "!!" ? That is a "not" operation and does nothing more than give you the reverse. Most likely the compiler is ignoring your bad code.
[toc] | [prev] | [next] | [standalone]
| From | supercat@casperkitty.com |
|---|---|
| Date | 2015-09-21 15:21 -0700 |
| Message-ID | <49e166c0-a765-4c6d-b499-e27d19f25487@googlegroups.com> |
| In reply to | #71045 |
On Monday, September 21, 2015 at 5:09:14 PM UTC-5, M Philbrook wrote: > I would like to know why you are using double "!!" ? > > That is a "not" operation and does nothing more than > give you the reverse. Using "!!x" is a shorthand way of writing "(x != 0)", but avoids use of the phony constant zero [the former expression tests whether x is non-zero, while the latter tests whether the value of x is something other than zero. Both expressions yield the same behavior, but the latter makes it look as though "x" could equally-sensibly be compared with any other value, while the former makes it clear (to anyone familiar with the idiom) that the purpose of the code is not to test whether "x" holds some particular combination of bits, but rather to check whether "x" has any bits set.
[toc] | [prev] | [next] | [standalone]
| From | Robert Wessel <robertwessel2@yahoo.com> |
|---|---|
| Date | 2015-09-21 17:51 -0500 |
| Message-ID | <id210btlsqe47v45golbv08mkesillqbnc@4ax.com> |
| In reply to | #71045 |
On Mon, 21 Sep 2015 18:15:23 -0400, M Philbrook <jamie_ka1lpa@charter.net> wrote: >In article <f3842$5600536b$d47876e2$45003@news.ziggo.nl>, skybuck2000 >@hotmail.com says... >> >> ! in C is supposed to be logical not. >> >> Not exactly sure what is ment with that... but to me it would seem this >> converts integers to boolean. >> >> So this could be some kind of integer to boolean conversion operator. >> >> Perhaps a typecast to boolean might help for Delphi. >> >> Anyway I also base this on inspecting the assembly a little bit... there was >> a cmp in it... which probably sets some flags... >> >> and then some kind of set instruction was executed. >> >> Just for the kick of it here it is: >> >> >> return ((!!x) | (x >> 31)); >> >> 010A13AE xor eax,eax >> >> 010A13B0 cmp dword ptr [x],0 >> >> 010A13B4 setne al >> >> 010A13B7 mov ecx,dword ptr [x] >> >> 010A13BA sar ecx,1Fh >> >> 010A13BD or eax,ecx >> >> >> >> Bye, >> >> Skybuck. > > I would like to know why you are using double "!!" ? > > That is a "not" operation and does nothing more than >give you the reverse. > > Most likely the compiler is ignoring your bad code. !! is a common C idiom for reducing a zero/non-zero value to zero/one.
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2015-09-21 19:15 -0400 |
| Message-ID | <56008F7B.3030501@verizon.net> |
| In reply to | #71051 |
On 09/21/2015 06:51 PM, Robert Wessel wrote: > On Mon, 21 Sep 2015 18:15:23 -0400, M Philbrook > <jamie_ka1lpa@charter.net> wrote: > >> In article <f3842$5600536b$d47876e2$45003@news.ziggo.nl>, skybuck2000 >> @hotmail.com says... >>> >>> ! in C is supposed to be logical not. >>> >>> Not exactly sure what is ment with that... but to me it would seem this >>> converts integers to boolean. >>> >>> So this could be some kind of integer to boolean conversion operator. >>> >>> Perhaps a typecast to boolean might help for Delphi. >>> >>> Anyway I also base this on inspecting the assembly a little bit... there was >>> a cmp in it... which probably sets some flags... >>> >>> and then some kind of set instruction was executed. >>> >>> Just for the kick of it here it is: >>> >>> >>> return ((!!x) | (x >> 31)); ... >> >> I would like to know why you are using double "!!" ? >> >> That is a "not" operation and does nothing more than >> give you the reverse. >> >> Most likely the compiler is ignoring your bad code. > > > !! is a common C idiom for reducing a zero/non-zero value to zero/one. Which doesn't seem particularly useful as the left operand of a bitwise-or operator in this context. My best guess is that he thought it mapped zero/non-zero to zero/(-1). For certain unportable assumptions about how x>>31 works for negative numbers, that would produce the right result. That would require that he have serious misconceptions about how the unary ! operator works - but the words above make it pretty clear that he's pretty much clueless about such things.
[toc] | [prev] | [next] | [standalone]
| From | Robert Wessel <robertwessel2@yahoo.com> |
|---|---|
| Date | 2015-09-21 23:59 -0500 |
| Message-ID | <nbn10bp5sddovanc3hsne1ai2fq93tgl0i@4ax.com> |
| In reply to | #71055 |
On Mon, 21 Sep 2015 19:15:07 -0400, James Kuyper <jameskuyper@verizon.net> wrote: >On 09/21/2015 06:51 PM, Robert Wessel wrote: >> On Mon, 21 Sep 2015 18:15:23 -0400, M Philbrook >> <jamie_ka1lpa@charter.net> wrote: >> >>> In article <f3842$5600536b$d47876e2$45003@news.ziggo.nl>, skybuck2000 >>> @hotmail.com says... >>>> >>>> ! in C is supposed to be logical not. >>>> >>>> Not exactly sure what is ment with that... but to me it would seem this >>>> converts integers to boolean. >>>> >>>> So this could be some kind of integer to boolean conversion operator. >>>> >>>> Perhaps a typecast to boolean might help for Delphi. >>>> >>>> Anyway I also base this on inspecting the assembly a little bit... there was >>>> a cmp in it... which probably sets some flags... >>>> >>>> and then some kind of set instruction was executed. >>>> >>>> Just for the kick of it here it is: >>>> >>>> >>>> return ((!!x) | (x >> 31)); >... >>> >>> I would like to know why you are using double "!!" ? >>> >>> That is a "not" operation and does nothing more than >>> give you the reverse. >>> >>> Most likely the compiler is ignoring your bad code. >> >> >> !! is a common C idiom for reducing a zero/non-zero value to zero/one. > >Which doesn't seem particularly useful as the left operand of a >bitwise-or operator in this context. > >My best guess is that he thought it mapped zero/non-zero to zero/(-1). >For certain unportable assumptions about how x>>31 works for negative >numbers, that would produce the right result. That would require that he >have serious misconceptions about how the unary ! operator works - but >the words above make it pretty clear that he's pretty much clueless >about such things. That Skybuck is clueless is a given. But assuming the desired behavior of signed shifts (obviously not guaranteed by the standard, but a not unlikely result on x86), the expression will evaluate as 1|-1 for a negative input, 0|0 for zero, or 1|0 for a positive input. Also assuming twos' complement, those will result in -1/0/1 for negative/zero/positive inputs. Obviously Delphi defines something in there differently.
[toc] | [prev] | [next] | [standalone]
| From | supercat@casperkitty.com |
|---|---|
| Date | 2015-09-22 09:22 -0700 |
| Message-ID | <bd1b9cab-9d05-4fac-8068-63f5079609d4@googlegroups.com> |
| In reply to | #71055 |
On Monday, September 21, 2015 at 6:15:24 PM UTC-5, James Kuyper wrote: > For certain unportable assumptions about how x>>31 works for negative > numbers, ... I really wish the C Standard would recognize categories of conformance between "strictly conforming" [doesn't use any features beyond those which the most perversely-designed implementation would be required to support] and "conforming" [works as required in some dialect somewhere]. I recognize that there exist implementations where right-shifts of negative numbers behave in some fashion other than floored division, there likely exists production code which relies upon such behavior, and mandating that those implementations start using the common behavior would break any code that relies upon something else, but I see no good reason why the existence of such implementations should preclude the possibility of saying "Absent a reason to do otherwise, two's-complement C implementations should implement the right-shift operator on signed values to perform floored division (which is the same as a sign-extending shift); implementations must define a macro which code that requires the typical behavior can use to refuse compilation on platforms that don't support it. The behaviors which emerged as normative in the 1990s and which dialects strove to support absent a compelling reason otherwise [even in cases where such support would require an extra instruction or two here and there] form a useful dialect. By contrast, the dialect of C required for a strictly- conforming program is uselessly anemic. Too bad nobody in the intervening decades has formalized a "normative" C standard.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2015-09-22 10:32 -0700 |
| Message-ID | <ln61329x6g.fsf@kst-u.example.com> |
| In reply to | #71099 |
supercat@casperkitty.com writes:
> On Monday, September 21, 2015 at 6:15:24 PM UTC-5, James Kuyper wrote:
>> For certain unportable assumptions about how x>>31 works for negative
>> numbers, ...
>
> I really wish the C Standard would recognize categories of conformance
> between "strictly conforming" [doesn't use any features beyond those which
> the most perversely-designed implementation would be required to support]
> and "conforming" [works as required in some dialect somewhere].
N1570 4p3:
A program that is correct in all other aspects, operating on
correct data, containing unspecified behavior shall be a correct
program and act in accordance with 5.1.2.3.
[...]
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | jt@toerring.de (Jens Thoms Toerring) |
|---|---|
| Date | 2015-09-22 18:17 +0000 |
| Message-ID | <d6dka0Fora6U1@mid.uni-berlin.de> |
| In reply to | #71099 |
supercat@casperkitty.com wrote:
> On Monday, September 21, 2015 at 6:15:24 PM UTC-5, James Kuyper wrote:
> > For certain unportable assumptions about how x>>31 works for negative
> > numbers, ...
> I really wish the C Standard would recognize categories of conformance
> between "strictly conforming" [doesn't use any features beyond those which
> the most perversely-designed implementation would be required to support]
> and "conforming" [works as required in some dialect somewhere].
> I recognize that there exist implementations where right-shifts of negative
> numbers behave in some fashion other than floored division, there likely
> exists production code which relies upon such behavior, and mandating that
> those implementations start using the common behavior would break any code
> that relies upon something else, but I see no good reason why the existence
> of such implementations should preclude the possibility of saying "Absent
> a reason to do otherwise, two's-complement C implementations should implement
> the right-shift operator on signed values to perform floored division (which
> is the same as a sign-extending shift); implementations must define a macro
> which code that requires the typical behavior can use to refuse compilation
> on platforms that don't support it.
> The behaviors which emerged as normative in the 1990s and which dialects
> strove to support absent a compelling reason otherwise [even in cases where
> such support would require an extra instruction or two here and there] form
> a useful dialect. By contrast, the dialect of C required for a strictly-
> conforming program is uselessly anemic. Too bad nobody in the intervening
> decades has formalized a "normative" C standard.
What would it actually be good for? When actually do you need to
right-shift signed integers? I've seen that done in two catego-
ries of code: one was very low level, platform dependent stuff,
where someone knew the behaviour of the underlying CPU and what
the compiler does very well (and thus had no trouble understanding
what the risks might be) and, on the other hand, in code by "cow-
boy" programmers that have some vague notion that bit-fiddling and
right-shifting would be faster than a division by a power of two,
and typically have no good idea what they are doing.
Would it be necessary to change the standard (with all possible
unintended consequences) for the benefits of the second group,
just to avoid trouble for them when they falsely assume that a
right-shift is identlical to an integer division by 2? And that
at the cost that people using C for very hardware-near program-
ming now wouldn't be able anymore to exploit what the CPU is
actually doing in highly time-critical situations?
To me your proposal with macros and other kind of stuff (like
distinguishing between 1's and 2's complement architectures)
sounds actually a lot more complicated than remembering the
simple rule that you just don't shift signed integers - there
is no good reason for doing it I can see in everyday code (and
the assumption that it's faster is likely to be wrong - if a
division can be made faster by replacing it by a shift that's
one of the easiest things for an optimizing compiler).
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
[toc] | [prev] | [next] | [standalone]
Page 1 of 8 [1] 2 3 4 5 6 7 8 Next page →
Back to top | Article view | comp.lang.c
csiph-web