Xojo Conferences
XDCMay2019MiamiUSA

[RB List] Here'z a bug for yah! (Real Studio getting started Mailinglist archive)

Back to the thread list
Previous thread: XML: RemoveChild Question
Next thread: Favorites ... Still can't figure it out


RE: [RB List] Starting a Thread   -   RBNUBE
  [RB List] Here'z a bug for yah!   -   Eirik Karlsen
    Re: [RB List] Here'z a bug for yah!   -   Seth Willits

[RB List] Here'z a bug for yah!
Date: 06.02.05 12:54 (Sun, 06 Feb 2005 12:54:08 +0100)
From: Eirik Karlsen
Strange things are happening in this code:
'**********************'

dim minutes,seconds,decseconds As double

Samples32 '10 samples/sec: 2minutes:33.20seconds
'---------- Statistics: --------------------------------
StaticTextSamples.text=str(Samples)
seconds minutes decseconds
minutesðoor((Samples/10)/60)
secondsðoor((Samples/10)-(minutes*60))
decseconds=( 10*((Samples/10)-minutes*60-seconds) )
decsecondsÞcseconds*10
'decseconds
'decsecondsðoor(decseconds)

StaticTextRunTime.text=str(minutes)+":"+str(seconds)+"."+str(decseconds)
'******************
Running this code gives 2:33.20 which is correct.
However if I enable this line: 'decsecondsðoor(decseconds)
then the result becomes 2:33.19 !??

If I also enable this line: 'decseconds
then the result becomes 2:33.20 which is correct.

Note that in the first case decimalseconds was 20 and not 19,999999999...

So this oddity cannot be contributed to floating point errors...it must be a
bug, right?


--
**

Re: [RB List] Here'z a bug for yah!
Date: 06.02.05 20:37 (Sun, 6 Feb 2005 11:37:01 -0800)
From: Seth Willits
On Feb 6, 2005, at 3:54 AM, Eirik Karlsen wrote:

> So this oddity cannot be contributed to floating point errors...it
> must be a
> bug, right?

Without even looking at what's happening I can guarantee it's not a
bug. :)

Why do you say that it can't be floating point errors? That's exactly
what's happening. Rather than using doubles everywhere and doing
floating point math, since you only need integers, use integers, and
rather than trying to construct decseconds from a fractional value (bad
idea!) work it the other way so it's always an integer.


dim minutes, seconds, decseconds, samples as Integer

Samples = 1532
minutes = (Samples / 10) / 60
seconds = (Samples / 10) - (minutes * 60)
decseconds = (samples - ((minutes * 60) * 10) - seconds * 10) * 10

StaticTextSamples.text = str(Samples)

StaticTextRunTime.text=str(minutes)+":"+str(seconds)+"."+str(decseconds)



Seth Willits
------------------------------------------------------------------------
---
President and Head Developer of Freak Software - http://www.freaksw.com
REALbasic Guru at ResExcellence - http://www.resexcellence.com/realbasic

"Rather fail with honor than succeed by fraud."
-- Sophocles
------------------------------------------------------------------------
---

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>