# [R] swap_tail macro in pnorm.c

Date: Mon, 14 Jul 2008 10:39:57 -0400

Hello,

Looking over the swap_tail macro in pnorm.c, the comment inside the code indicates it is to swap the values of '*cum' and '*ccum'. According to the code below that is taken from the source file, the swap functionality is dependent on what values are provided for 'x' and 'lower'.

#define swap_tail      \
if (x > 0.) {/* swap  ccum <--> cum */      \
temp = *cum; if(lower) *cum = *ccum; *ccum = temp;      \
}

It only swaps the corresponding values if and only if 'x' is greater than zero and 'lower' is "true" (non-zero). The following examples will show the actual behavior:

Input 1 Input 2
-------- --------
x: 1 x: 1
lower: 0 lower: 2
*cum: 1 *cum: 1
*ccum: 2 *ccum: 2

Result 1 Result 2
-------- --------
temp: 1 temp: 1
*cum: 1 *cum: 2
*ccum: 1 *ccum: 1

According to the code, Input 1 causes '*cum' to retain its value while '*ccum' loses its own and takes on that of '*cum', performing a half-swap. Input 2 performs the full swap, resulting in '*cum' taking on the original value of '*ccum' while '*ccum' takes on the original value of '*cum'.

Since the logic following the 'lower' conditional statement is not surrounded in braces, this causes the second statement (*ccum = temp;) to be executed even if 'lower' evaluates to "false" (zero). Is this an appropriate result for the macro since this does not actually result in a swapped pair of values, as indicated in the above example (Input 1)? Or should this only result in swapped values if and only if 'x' and 'lower' are greater than zero and non-zero, respectively?

--

http://www.cs.utk.edu/~athompso

[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help