| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | [C] Stepped round up |
From: Bruce Partridge I have to round up to a stepped list of values in an embedded system. It occurs a few times, and I looking for something that will be small/fast. The steps are multiples of 3, and the subject number is a float and the result is the nearest step that is greater than the subject_number. What I'm doing now is next_step = ((int)(subject_number / 3) * step_size) + step size This code generates a bunch of assembler code (including a float division) for what seems to be a simple requirement. This code will also falsely set the next_step one step too high if the subject_number happened to actually hit exactly on a step. I've checked the usual places like "Hackers Delight", but haven't found an inspired solution yet. Bruce Partridge http://www.rebreather.ca -+- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.564 / Virus Database: 356 - Release Date: 1/19/2004 --- BBBS/LiI v4.01 Flag-5* Origin: Prism's_Point (1:261/38.1) SEEN-BY: 633/267 270 @PATH: 261/38 123/500 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.