Re: Converting floats to a specific range

Oscar Forth <[email protected]> Fri, 7 May 2010 12:50:50 +0100
Newsgroups gmane.games.devel.algorithms
Message-ID <[email protected]>
Unless I'm being daft isn't it just:

x = fmodf( 1.0f + fmodf( f, 1.0f ), 1.0f );

?

And btw 1.0 IS a power of 2.  2^0 in fact ;)

On 7 May 2010 12:36, Zafar Qamar <[email protected]> wrote:

> Hi,
>
> I'm sure this problem is pretty simple, but here goes...
>
> I have a set of float numbers that I'm trying to auto-wrap within a
> specific range of 0.0 to wrapSize (wrapSize is positive, and not a power of
> 2)
>
> So, if I choose a wrapSize of 1.0 then I want the following to happen when
> I feed in numbers...
>
> -739.8 --> 0.2
> :
> :
> -1.1 --> 0.9
> -1.0 --> 0.0
> -0.9 --> 0.1
> :
> -0.2 --> 0.8
> -0.1 --> 0.9
> 0.0 --> 0.0
> 0.1 --> 0.1
> :
> 0.9 --> 0.9
> 1.0 --> 0.0
> 1.1 --> 0.1
> :
>
> Can anyone think of a bit of maths for this please? Note that it needs to
> work for any positive value of wrapSize (not just 1.0)
>
> Cheers
> Zafar
>
> **********************************************************************************
> Disclaimer
>
> The information and attached documentation in this e-mail is intended for
> the use of the addressee only and is confidential. If you are not the
> intended recipient please delete it and notify us immediately by telephoning
> or e-mailing the sender. Please note that without Codemasters’ prior written
> consent any form of distribution, copying or use of this communication or
> the information in it is strictly prohibited and may be unlawful.
>
> Attachments to this e-mail may contain software viruses. You are advised to
> take all reasonable precautions to minimise this risk and to carry out a
> virus check on any documents before they are opened.
>
> Any offer contained in this communication is subject to Codemasters’
> standard terms & conditions and must be signed by both parties. Except as
> expressly provided otherwise all information and attached documentation in
> this e-mail is subject to contract and Codemasters’ board approval.
> Any views or opinions expressed are solely those of the author and do not
> necessarily represent those of Codemasters.
>
> This footnote also confirms that this email message has been swept by
> SurfControl for the presence of computer viruses.
>
> **********************************************************************************
>
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> GDAlgorithms-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list
> Archives:
> http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list

------------------------------------------------------------------------------

_______________________________________________
GDAlgorithms-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list