Re: [Algorithms] Converting floats to a specific range
Brought to you by:
vexxed72
From: Zafar Q. <zaf...@co...> - 2010-05-10 12:42:27
|
Cheers for your responses. And for the comedy one :) A couple of interesting ways of achieving the solution there. Much appreciated Zafar -----Original Message----- From: Chris Jenner [mailto:Chr...@ub...] Sent: 07 May 2010 12:57 To: Game Development Algorithms Subject: Re: [Algorithms] Converting floats to a specific range float wrap(float x) { Const float wrapSize = 1.0f; Return x - floorf(x/wrapSize)*wrapSize; } -----Original Message----- From: Zafar Qamar [mailto:zaf...@co...] Sent: 07 May 2010 12:36 To: Game Development Algorithms Subject: [Algorithms] Converting floats to a specific range 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 GDA...@li... https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list ------------------------------------------------------------------------------ _______________________________________________ GDAlgorithms-list mailing list GDA...@li... https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list ********************************************************************************** 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. ********************************************************************************** |