Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nx.as_type/2 loses precision on constants #1224

Closed
woodward opened this issue May 22, 2023 · 2 comments · Fixed by #1225
Closed

Nx.as_type/2 loses precision on constants #1224

woodward opened this issue May 22, 2023 · 2 comments · Fixed by #1225
Assignees

Comments

@woodward
Copy link
Contributor

Hi:

Here's an example which shows a loss of precision which seems a little surprising to me when using Nx.as_type/2:

iex(2)> Nx.as_type(0.38, :f64) |> IO.inspect()
#Nx.Tensor<
  f64
  0.3799999952316284
>

whereas Nx.tensor/2 does the following (which is correct for :f64):

iex(3)> Nx.tensor(0.38, type: :f64) |> IO.inspect()
#Nx.Tensor<
  f64
  0.38
>

Thank you for any help you can provide!

-- Greg

@polvalente polvalente self-assigned this May 22, 2023
@josevalim
Copy link
Collaborator

Duplicate of #448. :)

@josevalim
Copy link
Collaborator

I was wrong, not a dup. :)

@josevalim josevalim reopened this May 22, 2023
@polvalente polvalente linked a pull request May 22, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants