# Documentation : Scilab is Not Naive Commit Details

Date: 2010-12-20 11:32:04 (7 years 9 months ago) Michael Baudin 33 32 Fixed Stewart algorithm, with Corrigendum from TOMS/1986.

## File differences

en_US/scripts/cdiv_smithStewart.sci
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
 // Copyright (C) 2010 - Michael Baudin␊ ␊ ␊ // A Scilab port of Stewart's algorithm.␊ // References␊ //␊ // "A Note on Complex Division"␊ // G. W. Stewart, University of Maryland␊ // ACM Transactions on Mathematical Software, Vol. 11␊ // No 3, September 1985, Pages 238-241␊ // ␊ // TODO : fix this using :␊ // G. W. Stewart␊ // Corrigendum: ``{A} Note on Complex Division''",␊ // TOMS,␊ // volume 12␊ // number 3␊ // pages = 285--285␊ // month = September, 1986␊ ␊ function r = cdiv_smithStewart ( x,y )␊ error("Does not work")␊ c = real(x)␊ d = imag(x)␊ e = real(y)␊ f = imag(y)␊ flip = %f␊ if ( abs(f) >= abs(e) ) then␊ [f,e]=switch(e,f)␊ [c,d]=switch(d,c)␊ flip=%t␊ end␊ s=1/e␊ t=1/(e+f*(f*s))␊ if ( abs(f) >= abs(s) ) then␊ [f,s]=switch(s,f)␊ end␊ if ( abs(d) >= abs(s) ) then␊ a=t*(c+s*(d*f))␊ elseif ( abs(d) >= abs(f) ) then␊ a=t*(c+d*(s*f))␊ else␊ a=t*(c+f*(s*d))␊ end␊ if ( abs(c) >= abs(s) ) then␊ b=t*(d+s*(c*f))␊ elseif ( abs(c) >= abs(f) ) then␊ b=t*(d+c*(s*f))␊ else␊ b=t*(d+f*(s*c))␊ end␊ if ( flip ) then␊ b=-b␊ end␊ // Avoid using x + %i * y, which may create␊ // %inf+%i*%inf, which actually multiplies 0 and %inf,␊ // generating an unwanted %nan.␊ r = complex(a,b)␊ endfunction␊ ␊ function [c,d]=switch(a,b)␊ c=a␊ d=b␊ endfunction␊ ␊ function r = cdiv_smithStewart_Other ( x,y )␊ c = real(x)␊ d = imag(x)␊ e = real(y)␊ f = imag(y)␊ flip = %f␊ if ( abs(f) >= abs(e) ) then␊ // Switch e and f␊ tmp=e␊ e=f␊ f=tmp␊ // Switch c and d␊ tmp=c␊ c=d␊ d=tmp␊ flip=%t␊ end␊ s=1/e␊ t=1/(e+f*(f*s))␊ if ( abs(f) >= abs(s) ) then␊ // Switch f and s␊ tmp=f␊ f=s␊ s=tmp␊ end␊ if ( abs(d) >= abs(s) ) then␊ a=t*(c+s*(d*f))␊ elseif ( abs(d) >= abs(f) ) then␊ a=t*(c+d*(s*f))␊ else␊ a=t*(c+f*(s*d))␊ end␊ if ( abs(c) >= abs(s) ) then␊ b=t*(d+s*(c*f))␊ elseif ( abs(c) >= abs(f) ) then␊ b=t*(d+c*(s*f))␊ else␊ b=t*(d+f*(s*c))␊ end␊ if ( flip ) then␊ b=-b␊ end␊ // Avoid using x + %i * y, which may create␊ // %inf+%i*%inf, which actually multiplies 0 and %inf,␊ // generating an unwanted %nan.␊ r = complex(a,b)␊ endfunction␊ ␊ // Copyright (C) 2010 - Michael Baudin␍␊ ␍␊ ␍␊ // A Scilab port of Stewart's algorithm.␍␊ // References␍␊ //␍␊ // "A Note on Complex Division"␍␊ // G. W. Stewart, University of Maryland␍␊ // ACM Transactions on Mathematical Software, Vol. 11␍␊ // No 3, September 1985, Pages 238-241␍␊ // ␍␊ // G. W. Stewart␍␊ // Corrigendum: ``{A} Note on Complex Division''",␍␊ // TOMS, Volume 12, Number 3, Pages = 285--285, September, 1986␍␊ ␍␊ function r = cdiv_smithStewart ( x,y )␍␊ c = real(x)␍␊ d = imag(x)␍␊ e = real(y)␍␊ f = imag(y)␍␊ flip = %f␍␊ if ( abs(f) >= abs(e) ) then␍␊ [f,e]=switch(e,f)␍␊ [c,d]=switch(d,c)␍␊ flip=%t␍␊ end␍␊ s=1/e␍␊ t=1/(e+f*(f*s))␍␊ if ( abs(f) >= abs(s) ) then␍␊ [f,s]=switch(s,f)␍␊ end␍␊ if ( abs(d) >= abs(s) ) then␍␊ a=t*(c+s*(d*f))␍␊ elseif ( abs(d) >= abs(f) ) then␍␊ a=t*(c+d*(s*f))␍␊ else␍␊ a=t*(c+f*(s*d))␍␊ end␍␊ if ( abs(c) >= abs(s) ) then␍␊ b=t*(d-s*(c*f))␍␊ elseif ( abs(c) >= abs(f) ) then␍␊ b=t*(d-c*(s*f))␍␊ else␍␊ b=t*(d-f*(s*c))␍␊ end␍␊ if ( flip ) then␍␊ b=-b␍␊ end␍␊ // Avoid using x + %i * y, which may create␍␊ // %inf+%i*%inf, which actually multiplies 0 and %inf,␍␊ // generating an unwanted %nan.␍␊ r = complex(a,b)␍␊ endfunction␍␊ ␍␊ function [c,d]=switch(a,b)␍␊ c=a␍␊ d=b␍␊ endfunction␍␊ ␍␊ function r = cdiv_smithStewart_Other ( x,y )␍␊ c = real(x)␍␊ d = imag(x)␍␊ e = real(y)␍␊ f = imag(y)␍␊ flip = %f␍␊ if ( abs(f) >= abs(e) ) then␍␊ // Switch e and f␍␊ tmp=e␍␊ e=f␍␊ f=tmp␍␊ // Switch c and d␍␊ tmp=c␍␊ c=d␍␊ d=tmp␍␊ flip=%t␍␊ end␍␊ s=1/e␍␊ t=1/(e+f*(f*s))␍␊ if ( abs(f) >= abs(s) ) then␍␊ // Switch f and s␍␊ tmp=f␍␊ f=s␍␊ s=tmp␍␊ end␍␊ if ( abs(d) >= abs(s) ) then␍␊ a=t*(c+s*(d*f))␍␊ elseif ( abs(d) >= abs(f) ) then␍␊ a=t*(c+d*(s*f))␍␊ else␍␊ a=t*(c+f*(s*d))␍␊ end␍␊ if ( abs(c) >= abs(s) ) then␍␊ b=t*(d+s*(c*f))␍␊ elseif ( abs(c) >= abs(f) ) then␍␊ b=t*(d+c*(s*f))␍␊ else␍␊ b=t*(d+f*(s*c))␍␊ end␍␊ if ( flip ) then␍␊ b=-b␍␊ end␍␊ // Avoid using x + %i * y, which may create␍␊ // %inf+%i*%inf, which actually multiplies 0 and %inf,␍␊ // generating an unwanted %nan.␍␊ r = complex(a,b)␍␊ endfunction␍␊ ␍␊
en_US/scripts/cdiv.tst
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172