[vtk-developers] float vs double

Volpe, Christopher R (Research) volpecr at crd.ge.com
Wed Aug 28 14:07:47 EDT 2002


Hi folks-
  Under MS VC++ there are *lots* of warnings about conversions of doubles to floats. Now, I don't
know what happens on other CPUs (sparc, mips, etc) but on X86 *everything* is computed in double
precision, even if all the arguments have type float [%]. So, I'd like to clean some of this stuff
up, to reduce the number of spurious warnings that hide the real warnings. I see two general
approaches:

1) Make the double-to-float conversions explicit, with a static_cast<float> and/or remove the need
for conversion by using float constants instead of double constants.
E.g.:
	  static float Pi() {return 3.14159265358979;};
becomes
	  static float Pi() {return 3.14159265358979f;}; // note "f" at end of constant
and
	  static float Norm(const float x[3]) {
	    return sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);};
becomes
	  static float Norm(const float x[3]) {
	    return static_cast<float> sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);};

--- OR ---

2) Change occurrences of "float" to "double" where appropriate.
E.g.:
	  static float Pi() {return 3.14159265358979;};
becomes
	  static double Pi() {return 3.14159265358979;};

I'd prefer (2) because forcing things to be float rather than double incurs extra run-time
conversions (on X86). However, (1) might be a better choice if other architectures actually do
single-precision arithmetic internally, and do it faster than double-precision arithmetic. Ideally,
it might be better to typedef vtkReal on a per-architecture basis depending on which type is fastest
on the given platform, and use that instead, but I know that's too much to ask for. 

Any comments?


[%] The exception is if you explicitly put the processor in single precision mode. And even then, the
only thing this affects is divides and square roots. Everything else is still double precision.
Chris
> GE Global Research Center 
> ___________________________________________________________________________________________________
> _______________________________________________
> 
Dr. Christopher R. Volpe, Ph.D.
Computer Scientist
Visualization and Computer Vision Lab 
Imaging Technologies
Bldg KW, Room C215
P.O. Box 8, Schenectady, NY 12301

(518) 387-7766, Dial Comm: 8*833-7766, Fax: (518) 387-6981
e-mail: volpecr at research.ge.com    web: http://www.crd.ge.com/~volpecr




begin 600 winmail.dat
M>)\^(C(2`0:0"``$```````!``$``0>0!@`(````Y`0```````#H``$(@`<`
M&````$E032Y-:6-R;W-O9G0 at 36%I;"Y.;W1E`#$(`06``P`.````T@<(`!P`
M#@`'`"\``P!$`0$@@`,`#@```-('"``<``X`!P`N``,`0P$!"8`!`"$````X
M13(Y0S0X1#%!1CA%031!038X-34V,C at P,45",D$T.0!'!P$$@`$`$````&9L
M;V%T('9S(&1O=6)L90"Z!0$-@`0``@````(``@`!`Y`&`'0,```O`````P`)
M60,````"`7$``0```!8````!PDZ]T\2DI#)C4X=.H*UH7R=%IDO)```#`-X_
MKV\```,``6X@`````P`]@`@@!@``````P````````$8`````4H4``'UN`0`>
M`#Z`""`&``````#`````````1@````!4A0```0````0````Y+C``"P#J at 0@@
M!@``````P````````$8`````!H4````````#`#^`""`&``````#`````````
M1@`````!A0````````L`.X`((`8``````,````````!&``````.%````````
M"P!`@`@@!@``````P````````$8`````#H4````````#`#R`""`&``````#`
M````````1@`````0A0````````,`08`((`8``````,````````!&`````!&%
M`````````P!"@`@@!@``````P````````$8`````&(4````````"`0D0`0``
M``0'````!P``)PP``$Q:1G6&8R"%`P`*`')C<&<Q,C46,@#X"V!N#A`P,S-/
M`?<"I`/C`@!C:`K`<_!E=#`@!Q,"@P!0!.5Q`@!P<G$.4!#6#C`U?P8`!0,"
M at Q+Q$'42PA%I,[L#QA%X-!2;$,\"DC4#QIL%ZP*`?0J`",@@.PEO]Q.1&],.
M(#@)M!UR"C(=<5\;TQ.1";L"@`J!=@B0=\IK"X!D%T!U8P!0"P,A"[4 at 2&D@
M`A!L:XQS+0JB"H`@(%4 at L`,$D`725D,K*R!TLF@$D&4@"L`D,"H)``!T<RH@
M;V8@=_\*P`,`#R`$(`&@"&`%0`6@?&YV!)``D`(@!"`E`61G"&`"8`>1=&\B
M(`D`804DP"X'L&]W+"!)R2<!;B<%0&MN*%`E(.<84`5`&%!P<`GP)L$#H$,D
ML"0!($-0500@**IS"K%C*'!M!2!S*'!A$3!C*2!B)?$J,5C4.#8D@&4F47DC
M\"5QYR3@!``F$6UP)?`)@"VP^P.@)Q0@$L`%D`0`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0TA225-43U!(15(N5D],4$4`
M```#`!E```````,`)@```````P`V```````#`(`0_____PL`\A`!`````@%'
M``$````V````8SU54SMA/4U!4DLT,#`[<#U'13ML/5A-0C`R0U)$1T4M,#(P
M.#(X,3 at P-S0W6BTX-#0U-S,````"`?D_`0```'4`````````W*=`R,!"$!JT
MN0@`*R_A@@$`````````+T\]1T4O3U4]0U)$3DE32T%954Y!+T-./5)%0TE0
M245.5%,O0TX]15A#2$%.1T4 at 0TQ)14Y4("A%6$,P,4-21$=%*2]#3CU#2%))
M4U1/4$A%4BY63TQ010`````>`/@_`0```!L```!6;VQP92P at 0VAR:7-T;W!H
M97(@4B`H0U)$*0``'@`X0`$````2````0TA225-43U!(15(N5D],4$4````"
M`?L_`0```'4`````````W*=`R,!"$!JTN0@`*R_A@@$`````````+T\]1T4O
M3U4]0U)$3DE32T%954Y!+T-./5)%0TE0245.5%,O0TX]15A#2$%.1T4 at 0TQ)
M14Y4("A%6$,P,4-21$=%*2]#3CU#2%))4U1/4$A%4BY63TQ010`````>`/H_
M`0```!L```!6;VQP92P at 0VAR:7-T;W!H97(@4B`H0U)$*0``'@`Y0`$````2
M````0TA225-43U!(15(N5D],4$4```!```<PH(JJT+U.P@%```@P#)8.T+U.
MP@$>`#T``0````$`````````'@`=#@$````0````9FQO870@=G, at 9&]U8FQE
M`!X`-1`!````-@```#Q&0D4Y,$1&0S(T,$)!-30Q0C,X030S1C,Y.3$S03$V
M1#`R14$S,S)#0'AM8C`R8W)D9V4^````"P`I```````+`",```````,`!A!)
MBRP>`P`'$*L&```#`!`0``````,`$1``````'@`($`$```!E````2$E&3TQ+
M4RU53D1%4DU35D,K*U1(15)%05)%*DQ/5%,J3T9705).24Y'4T%"3U540T].
M5D524TE/3E-/1D1/54),15-43T9,3T%44TY/5RQ)1$].5$M.3U=72$%42$%0
M4$5.4P`````"`7\``0```#8````\1D)%.3!$1D,R-#!"034T,4(S.$$T,T8S
A.3DQ,T$Q-D0P,D5!,S,R0T!X;6(P,F-R9&=E/@````!Z
`
end



More information about the vtk-developers mailing list