Filip:
*NetworkAddressLength = (UINT)((j+1)/2);
Do not equal to
- if ((j % 2) == 0) ////// if even
- {
*NetworkAddressLength = (UINT)(j/2);- }
- else
- {
*NetworkAddressLength = (UINT)((j/2)+1);- }
2009/8/23 Filip Navara filip.navara@gmail.com
On Fri, Aug 21, 2009 at 5:57 PM, sginsberg@svn.reactos.org wrote:
--- trunk/reactos/drivers/network/ndis/ndis/config.c [iso-8859-1]
(original)
+++ trunk/reactos/drivers/network/ndis/ndis/config.c [iso-8859-1] Fri Aug
21 17:57:26 2009
@@ -705,7 +705,14 @@
while (j < str.Length && str.Buffer[j] != '\0') j++;
- *NetworkAddressLength = (UINT)((j/2)+0.5);
- if ((j % 2) == 0)
- {
*NetworkAddressLength = (UINT)(j/2);- }
- else
- {
*NetworkAddressLength = (UINT)((j/2)+1);- }
Why not use *NetworkAddressLength = (UINT)((j+1)/2); unconditionally?
if ((*NetworkAddressLength) == 0) {F.
Ros-dev mailing list Ros-dev@reactos.org http://www.reactos.org/mailman/listinfo/ros-dev
--- On Fri, 9/11/09, Wladimir A. Jimenez B. wjimenez@kasbeel.cl wrote:
Filip:
*NetworkAddressLength = (UINT)((j+1)/2); Do not equal to
- if ((j % 2) == 0) ////// if even
- {
- *NetworkAddressLength = (UINT)(j/2);
- }
- else
- {
- *NetworkAddressLength = (UINT)((j/2)+1);
- }
The only time when they would differ is if j == UINT_MAX (the shorter version would overflow). But that can never happen, since j is the length of a string.
To check odd / even we should always use:
// if odd
If (x & 1)
// if even
If (!x & 1)
% is very slow.
Jose Catena
DIGIWAVES S.L.
From: ros-dev-bounces@reactos.org [mailto:ros-dev-bounces@reactos.org] On Behalf Of Wladimir A. Jimenez B. Sent: Friday, 11 September, 2009 16:56 To: ReactOS Development List Subject: Re: [ros-dev] [ros-diffs] [sginsberg] 42829: - svchost: #ifdef _MSC_VER doesn't mean "using Microsoft's headers" anymore - ddraw, imm32, msxml3, oleaut32, riched20: Include typeof.h for typeof emulation when compiling under MSVC and remove from React
Filip:
*NetworkAddressLength = (UINT)((j+1)/2);
Do not equal to
- if ((j % 2) == 0) ////// if even
- {
*NetworkAddressLength = (UINT)(j/2);- }
- else
- {
*NetworkAddressLength = (UINT)((j/2)+1);- }
2009/8/23 Filip Navara filip.navara@gmail.com
On Fri, Aug 21, 2009 at 5:57 PM, sginsberg@svn.reactos.org wrote:
--- trunk/reactos/drivers/network/ndis/ndis/config.c [iso-8859-1]
(original)
+++ trunk/reactos/drivers/network/ndis/ndis/config.c [iso-8859-1] Fri Aug
21 17:57:26 2009
@@ -705,7 +705,14 @@
while (j < str.Length && str.Buffer[j] != '\0') j++;
- *NetworkAddressLength = (UINT)((j/2)+0.5);
- if ((j % 2) == 0)
- {
*NetworkAddressLength = (UINT)(j/2);- }
- else
- {
*NetworkAddressLength = (UINT)((j/2)+1);- }
Why not use *NetworkAddressLength = (UINT)((j+1)/2); unconditionally?
if ((*NetworkAddressLength) == 0) {
F.
_______________________________________________ Ros-dev mailing list Ros-dev@reactos.org http://www.reactos.org/mailman/listinfo/ros-dev
"If (!x & 1)" is the most horrible way to write this. To most people it means "NOT X AND 1", what you want is NOT(X AND 1).
Best regards, Alex Ionescu
On Fri, Sep 11, 2009 at 7:31 PM, Jose Catena jc1@diwaves.com wrote:
To check odd / even we should always use:
// if odd
If (x & 1)
// if even
If (!x & 1)
% is very slow.
Jose Catena
DIGIWAVES S.L.
From: ros-dev-bounces@reactos.org [mailto:ros-dev-bounces@reactos.org] On Behalf Of Wladimir A. Jimenez B. Sent: Friday, 11 September, 2009 16:56 To: ReactOS Development List Subject: Re: [ros-dev] [ros-diffs] [sginsberg] 42829: - svchost: #ifdef _MSC_VER doesn't mean "using Microsoft's headers" anymore - ddraw, imm32, msxml3, oleaut32, riched20: Include typeof.h for typeof emulation when compiling under MSVC and remove from React
Filip:
*NetworkAddressLength = (UINT)((j+1)/2);
Do not equal to
- if ((j % 2) == 0) ////// if even
- {
- *NetworkAddressLength = (UINT)(j/2);
- }
- else
- {
- *NetworkAddressLength = (UINT)((j/2)+1);
- }
2009/8/23 Filip Navara filip.navara@gmail.com
On Fri, Aug 21, 2009 at 5:57 PM, sginsberg@svn.reactos.org wrote:
--- trunk/reactos/drivers/network/ndis/ndis/config.c [iso-8859-1] (original) +++ trunk/reactos/drivers/network/ndis/ndis/config.c [iso-8859-1] Fri Aug 21 17:57:26 2009 @@ -705,7 +705,14 @@
while (j < str.Length && str.Buffer[j] != '\0') j++;
- *NetworkAddressLength = (UINT)((j/2)+0.5);
- if ((j % 2) == 0)
- {
- *NetworkAddressLength = (UINT)(j/2);
- }
- else
- {
- *NetworkAddressLength = (UINT)((j/2)+1);
- }
Why not use *NetworkAddressLength = (UINT)((j+1)/2); unconditionally?
if ((*NetworkAddressLength) == 0) {
F.
Ros-dev mailing list Ros-dev@reactos.org http://www.reactos.org/mailman/listinfo/ros-dev
--
Wladimir A. Jiménez B. http://www.kasbeel.cl Linux User # 444661 Ubuntu User # 19201
Ros-dev mailing list Ros-dev@reactos.org http://www.reactos.org/mailman/listinfo/ros-dev
Instead of (UINT)((j/2)+0.5)
Better (UINT)((j+1)>>1)
Much faster, and avoids unnecessary FPU and division usage. Many compilers will translate /2 to >>1, but none will change the way of rounding.
Jose Catena
DIGIWAVES S.L.
From: ros-dev-bounces@reactos.org [mailto:ros-dev-bounces@reactos.org] On Behalf Of Wladimir A. Jimenez B. Sent: Friday, 11 September, 2009 16:56 To: ReactOS Development List Subject: Re: [ros-dev] [ros-diffs] [sginsberg] 42829: - svchost: #ifdef _MSC_VER doesn't mean "using Microsoft's headers" anymore - ddraw, imm32, msxml3, oleaut32, riched20: Include typeof.h for typeof emulation when compiling under MSVC and remove from React
2009/8/23 Filip Navara filip.navara@gmail.com
On Fri, Aug 21, 2009 at 5:57 PM, sginsberg@svn.reactos.org wrote:
--- trunk/reactos/drivers/network/ndis/ndis/config.c [iso-8859-1]
(original)
+++ trunk/reactos/drivers/network/ndis/ndis/config.c [iso-8859-1] Fri Aug
21 17:57:26 2009
@@ -705,7 +705,14 @@
while (j < str.Length && str.Buffer[j] != '\0') j++;
- *NetworkAddressLength = (UINT)((j/2)+0.5);
- if ((j % 2) == 0)
- {
*NetworkAddressLength = (UINT)(j/2);- }
- else
- {
*NetworkAddressLength = (UINT)((j/2)+1);- }
Why not use *NetworkAddressLength = (UINT)((j+1)/2); unconditionally?
if ((*NetworkAddressLength) == 0) {
F.
_______________________________________________ Ros-dev mailing list Ros-dev@reactos.org http://www.reactos.org/mailman/listinfo/ros-dev
Hi,
Better (UINT)((j+1)>>1)
Where have you been 3 weeks ago? :) Somebody already implemented it: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/ndis/ndis/config.c?revision=42838&view=markup#l_708
// if even
If (!x & 1)
If the code and the comments disagree, then both are probably wrong. ;)
// if even If (!x & 1)
If the code and the comments disagree, then both are probably wrong. ;)
Indeed, I was wrong in the even example. It's: if (~x & 1) // or if (!(x & 1))
And yes, I just saw it was already implemented, sorry.
Jose Catena DIGIWAVES S.L.