<badcfe>
i would like to do in forth as in c when (unsigned)i, which is like a re-interpret-cast as in c++
<badcfe>
hmm. i see i must rephrase the problem. teh context is that i want to do as in forth 32768 mod but considering the number on the stack as if it was re-interpreted as unsigned regarding the semantics of the msb
<badcfe>
looking at the behavior of mod, it seems i'll merely 1+ when i have a negative number
<badcfe>
and bitwize not it
<badcfe>
something like that, manually. unless there is something more efficient
<MrMobius>
badcfe, what are you trying to do exactly?
<badcfe>
rather, s>d but without sign-extending it
<MrMobius>
there is u> for example to compare
<badcfe>
MrMobius: exactly? .. as in C the following (unsigned(rnd_next/65536) % 32768) / 32768.0
<badcfe>
MrMobius: it is part of the pseudo random example on my rand 2 man
<badcfe>
MrMobius: practicing forth here
<badcfe>
MrMobius: rnd_next is unsigned
<MrMobius>
you could AND with 0x3FFF to do mod 32768
<badcfe>
yes. but for the following f division i must consider it s>d without sign-extending it
<MrMobius>
youre trying to generate a random float between 0.0 and 1.0?
<badcfe>
yes.
<badcfe>
but i found this problem interesting by itself. as i am learning forth
<badcfe>
could i s>d without sign-extending prior to the f/ ?
<badcfe>
that is, as part of the s>d d>f that i would need
<badcfe>
the AND with 0x3FFF is excelent
<badcfe>
maybe i could shift the bits down, prior to s>d and then shift up again?
<badcfe>
that's what i could do instead of the AND there, in that case
<badcfe>
that, is if rshift is not "arithmetic" then i"m good to go
<badcfe>
doing -1 1 rshift, i see it's nice, but not sure if this is well defined behavior
<badcfe>
15 rshift s>d 15 2lshift
<badcfe>
heh, how do i lshift a double word number?
<badcfe>
s>d is sign-extending
<badcfe>
in my case i can use a simple lshift tho. i'm good
<badcfe>
MrMobius: but when i call rnd i get numbers above 1
<badcfe>
oh, i see it. i must lshift the one below the top 0 added by s>d, not the 0
<badcfe>
MrMobius: but is the order of s>d defined?
<badcfe>
MrMobius: does forth define the order of msb lsb on the stack for a double word number?
<badcfe>
it seems i will merely 0 instead of s>d and i can just and like suggested anyway
Gromboli has quit [Quit: Leaving]
<badcfe>
correction MrMobius "you could AND with 0x3FFF to do mod 32768" should have been "you could AND with 0x7FFF to do mod 32768"
<badcfe>
MrMobius: ^
<MrMobius>
badcfe, sorry, got busy
<MrMobius>
not sure about order. you can just do a little check and see how your forth does it
<MrMobius>
there is the ANS standard for example but a lot of people make their own forth or use one someone else made, so a forth could be doing anything
<MrMobius>
ya 0x7FFF sorry
<badcfe>
no problem. and thank you !
<badcfe>
trying to write another nice function here
<badcfe>
: linear ( n i FP b a -- FP i*{b-a}/n+a ) fdup frot frot f- s>f f* s>f f/ f+ ;