TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Kurt Kuzba
from: Jasen Betts
date: 2004-04-06 16:55:18
subject: [C] way out ?

Hi Kurt.

04-Apr-04 05:28:20, Kurt Kuzba wrote to All


 KK> From: "Kurt Kuzba" 

 KK>  I noted that Excel has a rounded step-up function a bit earlier,
 KK>  and wondered briefly how they accomplished it, and consigned it
 KK>  to the depths of unconsciousness thereafter.  When the question
 KK>  came up, an answer just popped up from out of the soup.  Neat.
 KK>  There is no problem so complex that a nap can't help.  

I remember the discussion... ISTR asking for clarification on the numbers
involved.

here's another way to do the same thing but using floats only so you can use
bigger numbers, you can even make step equal to 0.5 :)

#include 
float stepup_if_above( float num, float step)
{
    float rounded = floor(num/step)*step;
    return rounded + ( (rounded==num) ? 0 : step );
}

(don't try it with fractional steps that don't have a power of two as the
divisor as rounding errors will throw the whole-number terms off-course.)

 -=> Bye <=-

---
* Origin: Darth Vader sleeps with a Teddywookie. (3:640/1042)
SEEN-BY: 633/267 270
@PATH: 640/1042 531 954 774/605 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™.