Why f64.sin().ceil() give inconsistent results based on the invocation?

While messing with sound waves, I found a behavior that (as a beginner), I can't understand - essentially, based on how I build an expression <f64>.sin().ceil(), I get different results.

For example:

    println!("sin+ceil+print:{}", -0.5587640495890891_f64.sin().ceil()); // => -1
    println!("{}", (  -0.5587640495890891_f64.sin()  ).ceil()); // => 0


IIUC you want (-0.55_f64).sin().ceil(), but compiler reads it as -(0.55_f64.sin().ceil()) and with the second line it's (-(0.55_f64.sin()).ceil(), which obviously is a different computation. For example, -0.0_f64.cos() returns -1.0, not 1.0 as some may expect. BTW clippy has a lint for this (on playground see Tools->Clippy).


Thanks for the reply!

I'm a bit puzzled by clippy, though. If I activate it on the playground, it doesn't say anything. I also use rust-analyzer, which applies it as well, and I didn't see it in my editor, either (I've double checked by running cargo clippy - nothing, either).

Huh, weird. -0.0_f64.cos() does result in a clippy warning, but not -0.0_f64.cos().ceil() or -0.0_f64.sin(). Probably it's worth to create an issue, if a similar one does not exist already.

UPD: Looks like it's unintended effect of resolving this issue. I've created a clippy issue for this bug.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.