On Tue, Dec 14, 2004 at 04:44:19PM -0500, Harvey J. Stein wrote: > However, I still get some weird notes & warnings from the > compiler. Maybe someone can clue me in on them.
> Converted ONE-NORMAL-RAND. > Compiling DEFUN ONE-NORMAL-RAND: > > File: /home/hjstein/Quadrus/bsmc-cl-min6.lisp > > In: DEFUN ONE-NORMAL-RAND > (DEFUN ONE-NORMAL-RAND () > (DECLARE (VALUES #)) > (LOOP > (LET* # > #))) > Note: Doing float to pointer coercion (cost 13) to "<return value>". If ONE-NORMAL-RAND is used in a context where its return value isn't known to be an unboxed double-float, it needs to box it. > Converted CALLPAY. > Compiling DEFUN CALLPAY: > > File: /home/hjstein/Quadrus/bsmc-cl-min6.lisp > > In: DEFUN CALLPAY > (DEFUN CALLPAY (S K) > (DECLARE (TYPE DOUBLE-FLOAT S K) (VALUES DOUBLE-FLOAT)) > (- (MAX S K) K)) > Note: Doing float to pointer coercion (cost 13) to "<return value>". Same as above. > Converted BSMC. > Compiling DEFUN BSMC: > > File: /home/hjstein/Quadrus/bsmc-cl-min6.lisp > > In: DEFUN BSMC > (LET* ((DT #) (DRIFT #) (VOL #) (SUMVAL 0.0d0)) > (DECLARE (TYPE # DT DRIFT VOL ...)) > (DOTIMES (I TRIALS) > (DECLARE #) > (LET # ..))) > Warning: The binding of SUMVAL is not a > (VALUES &OPTIONAL (DOUBLE-FLOAT (0.0d0)) &REST T): > 0.0d0 You initially bind SUMVAL to 0d0, which isn't a (double-float (0d0)). (It is a (double-float 0d0), however.) > (DOTIMES (I TRIALS) > (DECLARE (TYPE # I)) > (LET (#) > (DECLARE #) > (DOTIMES # # #) ..)) > --> DO BLOCK > ==> > (LET ((I 0) (#:G0 TRIALS)) > (DECLARE (TYPE UNSIGNED-BYTE I)) > (DECLARE (TYPE # I)) > (TAGBODY > (GO #:G2) ..)) > Warning: The binding of I is not a > (VALUES &OPTIONAL (INTEGER 1 1000000) &REST T): > 0 The value of an iteration variable in DOTIMES starts at 0. > (LET ((S 0.0d0)) > (DECLARE (TYPE # S)) > (DOTIMES (J STEPS) (DECLARE #) (INCF S #)) > (INCF SUMVAL (+ # #))) > Warning: The binding of S is not a > (VALUES &OPTIONAL (DOUBLE-FLOAT (0.0d0) 1.0d+100) &REST T): > 0.0d0 S is initially bound to 0d0, which is explicitly excluded, as above. > (DOTIMES (J STEPS) (DECLARE (TYPE # J)) (INCF S (ONE-NORMAL-RAND))) > --> DO BLOCK > ==> > (LET ((J 0) (#:G3 STEPS)) > (DECLARE (TYPE UNSIGNED-BYTE J)) > (DECLARE (TYPE # J)) > (TAGBODY (GO #:G5) #:G4 (INCF S #) (PSETQ J #) ...)) > Warning: The binding of J is not a > (VALUES &OPTIONAL (INTEGER 1 1000000) &REST T): > 0 Same as the DOTIMES above. > (DEFUN BSMC (S0 SIGMA MAT K R ...) > (DECLARE (TYPE # S0 SIGMA MAT ...) (TYPE FIXNUM STEPS TRIALS)) > "(BSMC S0 SIGMA MAT K R STEPS TRIALS &optional (debug ())) Returns > Black Scholes option price for an option with maturity MAT & strike K, > on a stock with initial price S0 and volatility SIGMA. Risk free rate ..) > Note: Doing float to pointer coercion (cost 13) to "<return value>". The same reason as the two above. > Byte Compiling Top-Level Form: > > Compilation unit finished. > 4 warnings > 3 notes > > Surprisingly, the compiler figured out that sumval & s aren't really > positive! Declaring them double-float instead of with a range got rid > of 2 of the warnings. Perhaps it did; I don't really know. What it definitely did do was figure out that 0d0 isn't of the type you declared. > But, what about the other warnings? The manual talks about using > integer ranges instead of fixnum, so as to avoid promotion to a > bignum. However, this seems to conflict with the definition of > dotimes, which seems to declare the interation variable to be an > unsigned-byte. What to do about this? I guess I don't need to > declare them, but then (if I recall correctly, I'll have to check to > make sure) I start getting notes about coersions again, and I have > trouble giving good declarations to the fixnum args to bsmc. When several (compatible) type declarations are given, the intersection of them is used. So, if you declare something that is already declared to be an unsigned-byte as a fixnum, it's effectively declared to be an (integer 0 most-positive-fixnum). > Once this is explained, all that's left to explain are the coersion to > pointer notes. They're there for when the function is used in a context where an unboxed float isn't wanted. If you don't intend to use any function other than BSMC, you could do something like (compile-file "bsmc.lisp" :block-compile t :entry-points '(bsmc)) which should get rid of the notes. However, when the function /is/ used inline, the boxing/unboxing part of the code isn't used. Regards, 'mr -- [Emacs] is written in Lisp, which is the only computer language that is beautiful. -- Neal Stephenson, _In the Beginning was the Command Line_
