Skip navigation.
 
mlRe: NSTimer or double to int cast (Bug?)
FROM : Dave Camp
DATE : Fri Jan 10 17:39:51 2003

Try changing the %d to a %ld ? I've had problems with that before...

Dave

On Friday, January 10, 2003, at 05:05 AM, Marco Binder wrote:

> OK, I set up a new project and copied the relevant lines. The whole
> project looks like this:
>
> @implementation Controller
>
> - (id) init {
>    if (self = [super init]) {
>        double interval = 1.0;
>        timer = [[NSTimer scheduledTimerWithTimeInterval:interval
> target:self selector:@selector(timerAction:) userInfo:nil repeats:YES]
> retain];
>    }
>    return self;
> }
>
> - (void) timerAction: (id) sender {
>    NSLog(@"- interval as returned: %f, interval as int: %d",[timer
> timeInterval], (int)[timer timeInterval]);
> }
>
> @end
>
> Maybe there is something wrong with the code, but I dont see it. And
> as before, this code results in the following being written to the
> console on my G4:
>
> ## Component Manager: attempting to find symbols in a component alias
> of type (regR/carP/x!bt)
> 2003-01-10 13:58:04.390 TimerTest[834] - interval as returned:
> 1.000000, interval as int: 1
> 2003-01-10 13:58:05.389 TimerTest[834] - interval as returned:
> 1.000000, interval as int: 1
> 2003-01-10 13:58:06.389 TimerTest[834] - interval as returned:
> 1.000000, interval as int: 1
>
> On the other hand on the G3 iBook:
>
> 2003-01-10 14:00:37.286 TimerTest[413] - interval as returned:
> 1.000000, interval as int: 0
> 2003-01-10 14:00:38.284 TimerTest[413] - interval as returned:
> 1.000000, interval as int: 0
> 2003-01-10 14:00:39.283 TimerTest[413] - interval as returned:
> 1.000000, interval as int: 0
>
> I am not making this up, and you are more than welcome to downlad the
> project at: http://www.sb-software.de/TimerTest.tgz
>
>
> I still think this is extremly strange and would appreciate any kind
> of explaination.
>
>
> marco
>
>
> Am Freitag, 10.01.03 um 08:55 Uhr schrieb Cameron Hayne:
>

>> On 9/1/03 1:50 pm, "Marco Binder" <<email_removed>> wrote:

>>> I made a simple countdown app on my G4,
>>> using a simple NSTimer (countDown), firing every 1.0 seconds.
>>> However:

>>>>  double interval = [countDown timeInterval];
>>>>  NSLog(@"time interval: %f, rounded: %d",interval,(int)interval);

>>> the above code gives, correctly on my G4:

>>>> 2003-01-09 16:55:56.750 CountDownApp[697] time interval: 1.000000,
>>>> rounded: 1

>>> But when running the app on an iMac G3 or my iBook (G3 obviously), it
>>> results in:

>>>> 2003-01-09 16:58:20.832 CountDownApp[697] time interval: 1.000000,
>>>> rounded: 0

>>
>> I cannot reproduce your problem on my iBook. I create a timer with:
>> double interval = 1.0;
>> NSTimer *timer = [NSTimer
>>                  scheduledTimerWithTimeInterval: interval
>>                                          target: self
>>                                        selector:
>> @selector(timeGentlemen:)
>>                                        userInfo: nil
>>                                          repeats: YES];
>> and then the method:
>> + (void)timeGentlemen:(NSTimer *)theTimer
>> {
>>    NSLog(@"It is now %@", [[NSDate date] description]);
>>    double value = [theTimer timeInterval];
>>    NSLog(@"%f %d", value, (int)value);
>> }
>> prints out:
>>  1.000000 1
>> every time.
>>
>> --
>> Cameron Hayne (<email_removed>)
>> Hayne of Tintagel
>>
>>

> --
> |\  /|      E-Mail: <email_removed>  WWW: www.marco-binder.de
> | \/ |        Telefon: 07531 / 94 19 94  Fax: 07531 / 94 19 92
> |    |ARCO        Snail-Mail: Banater Str. 3 - 78467 Konstanz
>      BINDER _____________________________________________________
> _______________________________________________
> cocoa-dev mailing list | <email_removed>
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
>
>

---
It is dark; you are likely to be eaten by a grue. -Zork
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlNSTimer or double to int cast (Bug?) Marco Binder Jan 9, 19:50
mlRe: NSTimer or double to int cast (Bug?) Cameron Hayne Jan 10, 08:55
mlRe: NSTimer or double to int cast (Bug?) Marco Binder Jan 10, 14:05
mlRe: NSTimer or double to int cast (Bug?) Cameron Hayne Jan 10, 16:07
mlRe: NSTimer or double to int cast (Bug?) Marco Binder Jan 10, 16:29
mlRe: NSTimer or double to int cast (Bug?) Chris Ridd Jan 10, 16:49
mlRe: NSTimer or double to int cast (Bug?) Dave Camp Jan 10, 17:39
mlRe: NSTimer or double to int cast (Bug?) Marco Binder Jan 10, 17:51
mlRe: NSTimer or double to int cast (Bug?) Chris Kane Jan 10, 21:03
mlRe: NSTimer or double to int cast (Bug?) Dietmar Planitzer Jan 10, 21:05
mlRe: Re: NSTimer or double to int cast (Bug?) Cameron Hayne Jan 10, 21:25
mlRe: NSTimer or double to int cast (Bug?) Chris Ridd Jan 11, 09:47
mlRe: NSTimer or double to int cast (Bug?) Marco Binder Jan 11, 15:35
mlRe: NSTimer or double to int cast (Bug?) Chris Ridd Jan 11, 16:33
mlRe: NSTimer or double to int cast (Bug?) Marco Binder Jan 11, 17:49
mlRe: NSTimer or double to int cast (Bug?) Dietmar Planitzer Jan 11, 23:21