compiled code with modedeclare



Compiled functions that use modedeclare(x,float)
can cause trouble; an example:

The contents of "try.mac" is

------------
f(x):=(modedeclare(x,float),x:float(x),x^2);
myfloat(x) := float(x);
g(x) := (modedeclare(x,float), x : myfloat(x), x^2);
------------

(%i1) load("c:/maxima/try.mac");
(%o1) c:/maxima/try.mac
(%i2) f(-1);
(%o2) 1.0
(%i3) g(-1);
(%o3) 1.0

These are OK.  Let's translate try.mac.

(%i4) translate_file("c:/maxima/try.mac")$
(%i5) load("c:/maxima/try.lisp")$
(%i6) f(-1);
(%o6) 1
(%i7) g(-1);
(%o7) 1.0

These are OK, but I expected (%o6) to be 1.0 instead of 1.
The translated code for f is

(PROGN
  (DEFPROP |$f| T TRANSLATED)
  (ADD2LNC '|$f| $PROPS)
  (DEFMTRFUN (|$f| $FLOAT MDEFINE NIL NIL) (|$x|)
      (DECLARE (SPECIAL |$x|) (FLONUM |$x|))
      (PROGN NIL (SETQ |$x| |$x|) (EXPT$ |$x| 2))))

What's the story with  (setq |$x| |$x|)? I guess the
modedeclare tells Maxima that x is already a float,
so x : float(x) isn't needed?

Now, let's compile the code.

(%i8) compile_file("c:/maxima/try.mac")$
(%i9) load("c:/maxima/try.o")$
(%i10) f(-1);
(%o10) 0.0
(%i11) g(-1);
(%o11) 1.0

Yikes! Now f misbehaves.

Question: What is the best way to write a function like
f so that it doesn't misbehave when it's compiled?

Barton