Giter Site home page Giter Site logo

Comments (5)

soraros avatar soraros commented on June 29, 2024 1

Smaller repro:

fn main():
    print(int(UInt8(128)))  # prints -128

It's very curious that the following runs fine:

fn main():
  var n = UInt8(128)
  print(n)       # prints 128
  print(int(n))  # prints 128

from mojo.

fnands avatar fnands commented on June 29, 2024 1

Smaller repro:

fn main():
    print(int(UInt8(128)))  # prints -128

Similarly, running:

  var a: UInt32 = 129

  print(int(a.cast[DType.uint8]()))

in the REPL returns 129.

Running:

def main():
    var a: UInt32 = 129

    print(int(a.cast[DType.uint8]()))

main()

In the REPL returns -127

from mojo.

fnands avatar fnands commented on June 29, 2024

Just tested on nightly and behaviour is identical.
Nightly version: mojo 2024.6.1705 (79838f00)

from mojo.

soraros avatar soraros commented on June 29, 2024

Related to #2860 and #3045.

The 1 is caused by implicit conversion. UInt32(...) doesn't do what you think it does.

from mojo.

fnands avatar fnands commented on June 29, 2024

So just to be clear:

The var vs alias differences seem to only appear when reading a value from a table.

So there might be two issues: the table one and the int() one.

from mojo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.