Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > Re: d>f and f>d...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 6 Topic 3792 of 4325
Post > Topic >>

Re: d>f and f>d missing in ficl and order for double cells?

by Andrew Haley <andrew29@[EMAIL PROTECTED] > Mar 2, 2008 at 06:02 PM

Frank Buss <fb@[EMAIL PROTECTED]
> wrote:
> Looks like these 2 words are missing in ficl. Maybe there are other
useful
> words to convert integers to floats and vice-versa?

> I need the conversion, so I've implemented a first hack:

> static void ficlPrimitiveD2F(ficlVm *vm)
> {
>         ficlInteger doubleLow;
>         ficlStackPopInteger(vm->dataStack);  // ignore double high
>         doubleLow = ficlStackPopInteger(vm->dataStack);
>         ficlStackPushFloat(vm->floatStack, (float) doubleLow);
> }

> static void ficlPrimitiveF2D(ficlVm *vm)
> {
>         float f = ficlStackPopFloat(vm->floatStack);
>         ficlInteger doubleLow = (ficlInteger) f;
>         ficlInteger doubleHigh = doubleLow < 0 ? -1 : 0;
>         ficlStackPu****nteger(vm->dataStack, doubleLow);
>         ficlStackPu****nteger(vm->dataStack, doubleHigh);
> }

> and the registering part:

> ficlDictionarySetPrimitive(dictionary, "d>f", ficlPrimitiveD2F,
> FICL_WORD_DEFAULT);
> ficlDictionarySetPrimitive(dictionary, "f>d", ficlPrimitiveF2D,
> FICL_WORD_DEFAULT);

> But this doesn't work. Looks like ficl saves a double in low/high
format.
> This is the output of Win32Forth:

> 12. . .
> 0 12

> and this on ficl (compiled on an ARM platform) :
> 12. . .
> 12 0

> Which one is the right one?

Win32Forth is right.


 I don't understand what the word "above" means
> in "3.1.4.1 Double-cell integers".

> For me it looks better to push the high value as the last item on stack,
> because then I can just drop it, if not needed, instead of "swap drop",

Exactly right.  That's the reason.

Andrew.
 




 6 Posts in Topic:
d>f and f>d missing in ficl and order for double cells?
Frank Buss <fb@[EMAIL   2008-03-02 17:01:00 
Re: d>f and f>d missing in ficl and order for double cells?
Andrew Haley <andrew29  2008-03-02 18:02:19 
Re: d>f and f>d missing in ficl and order for double cells?
Elizabeth D Rather <er  2008-03-02 08:45:21 
Re: d>f and f>d missing in ficl and order for double cells?
Frank Buss <fb@[EMAIL   2008-03-03 05:18:15 
Re: d>f and f>d missing in ficl and order for double cells?
Andrew Haley <andrew29  2008-03-03 10:58:35 
Re: d>f and f>d missing in ficl and order for double cells?
anton@[EMAIL PROTECTED]   2008-03-03 10:47:20 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 16:32:44 CST 2008.