[FRIAM] Euler's Identity in 3

uǝlƃ ↙↙↙ gepropella at gmail.com
Tue Mar 9 15:57:07 EST 2021


Bah! I'm an idiot. If I use f64, I get:

ln(e^iπ) = 0+3.141592653589793i
ln(-1) = 0+3.141592653589793i


On 3/9/21 12:54 PM, uǝlƃ ↙↙↙ wrote:
> So, I'm trying to learn Rust. And in thinking about the ontological status of mathematical representations of waves (https://arxiv.org/abs/2101.10873), I figured I'd validate Euler's identity:
> 
> fn main() {
>   let e = num::complex::Complex::new(std::f32::consts::E,0.);
>   let e2ip = e.powc(num::complex::Complex::new(0.,std::f32::consts::PI));
>   let i = num::complex::Complex::new(0.,1.);
>   println!("ln(e^iπ) = {}",e2ip.ln());
>   println!("ln(-1) = {}", i.powi(2).ln());
> }
> $ cargo run
> ln(e^iπ) = 0+3.1415925i
> ln(-1) = 0+3.141592653589793i
> 
> I don't have any idea if that's a reasonable way to do that, since I'm ignorant of Rust. But it's interesting to contrast it with R and Sage:
> 
> $ Rscript -e "log(exp(1)^((0+1i)*pi));log((0+1i)^2)"
> [1] 0+3.141593i
> [1] 0+3.141593i
> 
> sage: numerical_approx(ln(e^(i*pi)));numerical_approx(ln(i^2))
> 3.14159265358979*I
> 3.14159265358979*I
> 
> The precision difference between the 2 results in Rust is interesting. It's the same if I use powf() instead of powi(). Any clues? Or should I simply RTFM?
> 

-- 
↙↙↙ uǝlƃ



More information about the Friam mailing list