Stream: helpdesk (published)

Topic: 2pi as Float32


view this post on Zulip Júlio Hoffimann (Jan 19 2021 at 16:41):

What is the most appropriate method to produce 2pi in single precision? Do we need to explicitly convert from the double precision result?

view this post on Zulip Júlio Hoffimann (Jan 19 2021 at 16:42):

I have geometric algorithms with angles that need to do 2pi - theta and this is creating some type instabilities in single precision when theta is single

view this post on Zulip Júlio Hoffimann (Jan 19 2021 at 16:43):

So my question is: is there a method to convert the irrational pi to a single precision float directly?

view this post on Zulip Fredrik Ekre (Jan 19 2021 at 16:45):

Float32(pi)

view this post on Zulip Júlio Hoffimann (Jan 19 2021 at 16:50):

Yes, I guess that is the best option :smile:

view this post on Zulip Mason Protter (Jan 19 2021 at 16:52):

there's always

julia> 2f0π
6.2831855f0

view this post on Zulip Júlio Hoffimann (Jan 19 2021 at 16:58):

cool trick too :smile:

view this post on Zulip Júlio Hoffimann (Jan 19 2021 at 16:58):

but in this case I need to be generic with a type T(pi) inside a function

view this post on Zulip Mason Protter (Jan 19 2021 at 17:05):

You may be interested in ChangePrecision.jl

view this post on Zulip Mason Protter (Jan 20 2021 at 16:59):

@Júlio Hoffimann and @Fredrik Ekre would you mind if this was moved to #helpdesk (published)?

view this post on Zulip Júlio Hoffimann (Jan 20 2021 at 17:21):

Not at all :smile:

view this post on Zulip Notification Bot (Jan 20 2021 at 17:45):

This topic was moved here from #helpdesk > 2pi as Float32 by Mason Protter


Last updated: Oct 02 2023 at 04:34 UTC