Comments (3)
This appears to be another symptom of the issue described in #2860
from mojo.
I think this is definitely a bug since people trying to cast ints to floats or floats to ints would not reasonably expect their values to first be implicitly cast to bools.
from mojo.
I guess the correct way to change types is to do like this :
def main():
var y:Int = 1337
var y0 = Int32(y)
var y1 = y0.cast[DType.float32]()
var y2 = y1.cast[DType.uint32]()
print("y :",y)
print("y0 :",y0)
print("y1 :",y1)
print("y2 :",y2)
y0 = -1
y2 = y0.cast[DType.uint32]()
print("y2 :",y2)
because it seems to give expected answers
y : 1337
y0 : 1337
y1 : 1337.0
y2 : 1337
y2 : 4294967295
so, maybe not a bug but a misunderstanding.
If someone could confirm that's the correct way to do it, I'll be happy close the bug.
from mojo.
Related Issues (20)
- [Modular CLI] modular update mojo ends up in a segmentation fault HOT 1
- [Feature Request] [stdlib] [proposal] Unicode Indexing for `String` and buffer idx for `StringSlice` in `__getitem__` and `__setitem__` HOT 2
- [BUG] Get segmentation fault when build mojo and run it but don't get segmentation fault when run directly with mojo
- [BUG] stack_allocation fails HOT 1
- [Feature Request] Where clause alternative: "Composite Traits" `TraitVariant` (`|`) and `TraitUnion` (`&`)
- [BUG] Numpy imported into Mojo has inconsistent benchmarking results
- [Feature Request] Add benchmark for `Dict` and explore swiss table algorithm with SIMD probing HOT 6
- [Docs] Update Tensor docs
- [BUG] Cannot fold `__floordiv__` for `Int`
- [BUG] Python import not working - Linux|Conda HOT 1
- [Modular CLI][Documentation] modular --h and modular install -h do not list --install-version option
- Ability to Link to C Libraries
- [Docs] __new__ is not mentioned outside of the Change Log. HOT 1
- [stdlib] Allow `!r` in `String.format` HOT 1
- [stdlib][BUG] `InlineArray.__init__(inout self: Self, fill: ElementType)` compile-time SIGTERM when `size` parameter exceeds indeterministic value HOT 8
- [Feature Request] Rename `bit_ceil` and `bit_floor` to `closest_pow_2_ge` and `closest_pow_2_le`
- [Feature Request] Let `Variant` call methods without unwrapping the element when constrained on a trait
- [BUG][Compiler] Benchmark.Report does not calculate
- [BUG] Compiler seg fault (recursion related?) HOT 4
- [BUG] Parser accepts single `main` function without body
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mojo.