Why doesn't UInt have a toDouble()? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Generic Extension Property Receiver Type MismatchSmart-cast and comparison inside When Expression after 'is' type-checkHow to get ResultSet string array?How to extract kotlin-react html into a methodType mismatch using inject()-function from KoinReferencing list element inside of map in KotlinKotlin method references in place of lambdaAnko logger exception in callingKotlin - nullable receiver extension won't accept non-nullable equivalentUnresolved reference None of the following candidates is applicable because of receiver type mismatch
Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?
How does Belgium enforce obligatory attendance in elections?
Most bit efficient text communication method?
Do wooden building fires get hotter than 600°C?
What does this say in Elvish?
What is the difference between a "ranged attack" and a "ranged weapon attack"?
How to compare two different files line by line in unix?
Why do early math courses focus on the cross sections of a cone and not on other 3D objects?
How could we fake a moon landing now?
A term for a woman complaining about things/begging in a cute/childish way
In musical terms, what properties are varied by the human voice to produce different words / syllables?
preposition before coffee
What's the meaning of "fortified infraction restraint"?
What is an "asse" in Elizabethan English?
What do you call the main part of a joke?
How to save space when writing equations with cases?
How does the math work when buying airline miles?
Conditions when a permutation matrix is symmetric
Is there any word for a place full of confusion?
Is multiple magic items in one inherently imbalanced?
How many morphisms from 1 to 1+1 can there be?
Why are vacuum tubes still used in amateur radios?
What is the meaning of 'breadth' in breadth first search?
The Nth Gryphon Number
Why doesn't UInt have a toDouble()?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Generic Extension Property Receiver Type MismatchSmart-cast and comparison inside When Expression after 'is' type-checkHow to get ResultSet string array?How to extract kotlin-react html into a methodType mismatch using inject()-function from KoinReferencing list element inside of map in KotlinKotlin method references in place of lambdaAnko logger exception in callingKotlin - nullable receiver extension won't accept non-nullable equivalentUnresolved reference None of the following candidates is applicable because of receiver type mismatch
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Consider:
val foo: Int = 1
foo.toDouble() // ok
val bar = 2.toUInt()
bar.toDouble() // error!
This doesn't make sense to me. Why wouldn't UInt have toDouble
? (it also doesn't have .toFloat
).
The docs say:
Every number type supports the following conversions:
- toByte(): Byte
- toShort(): Short
- toInt(): Int
- toLong(): Long
- toFloat(): Float
- toDouble(): Double
- toChar(): Char
So it should be possible. The error I get is:
Error:(11, 4) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
@InlineOnly public inline fun String.toDouble(): Double defined in kotlin.text
Is UInt not considered a number type? Or is it something else?
kotlin
add a comment |
Consider:
val foo: Int = 1
foo.toDouble() // ok
val bar = 2.toUInt()
bar.toDouble() // error!
This doesn't make sense to me. Why wouldn't UInt have toDouble
? (it also doesn't have .toFloat
).
The docs say:
Every number type supports the following conversions:
- toByte(): Byte
- toShort(): Short
- toInt(): Int
- toLong(): Long
- toFloat(): Float
- toDouble(): Double
- toChar(): Char
So it should be possible. The error I get is:
Error:(11, 4) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
@InlineOnly public inline fun String.toDouble(): Double defined in kotlin.text
Is UInt not considered a number type? Or is it something else?
kotlin
possibly related: some architectures (notably x86) don't have native machine instructions to convert unsigned integers to floating point, only signed. (AVX512 finally adds that for x86, but it's still not widely available and very far from becoming baseline). Zero-extending to a wider signed integer type is by far the easiest implementation of unsigned->float or double when that's possible, but for 64-bit unsigned integers you need special tricks. Maybe Kotlin wanted to avoid that? But given that it runs on top of JVM or Javascript, maybe something else.
– Peter Cordes
Apr 12 at 3:43
@PeterCordes I doubt that any language would want to restrict itself to a single architecture's shortcomings. I mean even C allows this :) But interesting info nonetheless, thanks.
– Rakete1111
Apr 12 at 7:41
add a comment |
Consider:
val foo: Int = 1
foo.toDouble() // ok
val bar = 2.toUInt()
bar.toDouble() // error!
This doesn't make sense to me. Why wouldn't UInt have toDouble
? (it also doesn't have .toFloat
).
The docs say:
Every number type supports the following conversions:
- toByte(): Byte
- toShort(): Short
- toInt(): Int
- toLong(): Long
- toFloat(): Float
- toDouble(): Double
- toChar(): Char
So it should be possible. The error I get is:
Error:(11, 4) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
@InlineOnly public inline fun String.toDouble(): Double defined in kotlin.text
Is UInt not considered a number type? Or is it something else?
kotlin
Consider:
val foo: Int = 1
foo.toDouble() // ok
val bar = 2.toUInt()
bar.toDouble() // error!
This doesn't make sense to me. Why wouldn't UInt have toDouble
? (it also doesn't have .toFloat
).
The docs say:
Every number type supports the following conversions:
- toByte(): Byte
- toShort(): Short
- toInt(): Int
- toLong(): Long
- toFloat(): Float
- toDouble(): Double
- toChar(): Char
So it should be possible. The error I get is:
Error:(11, 4) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
@InlineOnly public inline fun String.toDouble(): Double defined in kotlin.text
Is UInt not considered a number type? Or is it something else?
kotlin
kotlin
asked Apr 11 at 16:06
Rakete1111Rakete1111
35.8k1086123
35.8k1086123
possibly related: some architectures (notably x86) don't have native machine instructions to convert unsigned integers to floating point, only signed. (AVX512 finally adds that for x86, but it's still not widely available and very far from becoming baseline). Zero-extending to a wider signed integer type is by far the easiest implementation of unsigned->float or double when that's possible, but for 64-bit unsigned integers you need special tricks. Maybe Kotlin wanted to avoid that? But given that it runs on top of JVM or Javascript, maybe something else.
– Peter Cordes
Apr 12 at 3:43
@PeterCordes I doubt that any language would want to restrict itself to a single architecture's shortcomings. I mean even C allows this :) But interesting info nonetheless, thanks.
– Rakete1111
Apr 12 at 7:41
add a comment |
possibly related: some architectures (notably x86) don't have native machine instructions to convert unsigned integers to floating point, only signed. (AVX512 finally adds that for x86, but it's still not widely available and very far from becoming baseline). Zero-extending to a wider signed integer type is by far the easiest implementation of unsigned->float or double when that's possible, but for 64-bit unsigned integers you need special tricks. Maybe Kotlin wanted to avoid that? But given that it runs on top of JVM or Javascript, maybe something else.
– Peter Cordes
Apr 12 at 3:43
@PeterCordes I doubt that any language would want to restrict itself to a single architecture's shortcomings. I mean even C allows this :) But interesting info nonetheless, thanks.
– Rakete1111
Apr 12 at 7:41
possibly related: some architectures (notably x86) don't have native machine instructions to convert unsigned integers to floating point, only signed. (AVX512 finally adds that for x86, but it's still not widely available and very far from becoming baseline). Zero-extending to a wider signed integer type is by far the easiest implementation of unsigned->float or double when that's possible, but for 64-bit unsigned integers you need special tricks. Maybe Kotlin wanted to avoid that? But given that it runs on top of JVM or Javascript, maybe something else.
– Peter Cordes
Apr 12 at 3:43
possibly related: some architectures (notably x86) don't have native machine instructions to convert unsigned integers to floating point, only signed. (AVX512 finally adds that for x86, but it's still not widely available and very far from becoming baseline). Zero-extending to a wider signed integer type is by far the easiest implementation of unsigned->float or double when that's possible, but for 64-bit unsigned integers you need special tricks. Maybe Kotlin wanted to avoid that? But given that it runs on top of JVM or Javascript, maybe something else.
– Peter Cordes
Apr 12 at 3:43
@PeterCordes I doubt that any language would want to restrict itself to a single architecture's shortcomings. I mean even C allows this :) But interesting info nonetheless, thanks.
– Rakete1111
Apr 12 at 7:41
@PeterCordes I doubt that any language would want to restrict itself to a single architecture's shortcomings. I mean even C allows this :) But interesting info nonetheless, thanks.
– Rakete1111
Apr 12 at 7:41
add a comment |
3 Answers
3
active
oldest
votes
Is UInt not considered a number type?
Yes, it doesn't extend Number
class.
Declaration of Int
:
class Int : Number, Comparable<Int>
Declaration of UInt
:
inline class UInt : Comparable<UInt>
Starting with Kotlin version 1.3.30 UInt
has toFloat
and toDouble
methods.
1
Thanks, that was surprising. Is there a way to convert aUInt
to aDouble
in some other way?
– Rakete1111
Apr 11 at 16:14
3
@Rakete1111 Trybar.toLong.toDouble()
– Andrew Churilo
Apr 11 at 16:18
add a comment |
This appears to be coming in 1.3.30, according to this YouTrack request.
1.3.30 was just recently tagged and appears to be releasing very shortly.
add a comment |
Added support in latest version 1.3.30
.
This release (More) brings support for more operations for unsigned types and arrays of unsigned types that mirror those for regular number types:
fun main()
val u1 = 2_147_483_649u
val u2 = 4_000_000_000u
println(u1.toDouble())
println(minOf(u1, u2))
val array: UIntArray = uintArrayOf(u1, u2)
println(array.max())
println(array.all it > Int.MAX_VALUE.toUInt() )
Note: UInt doesn't extend Number class.
/**
* Converts this [UInt] value to [Double].
*
* The resulting `Double` value represents the same numerical value as this `UInt`.
*/
@kotlin.internal.InlineOnly
public inline fun toDouble(): Double = uintToDouble(data)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55636856%2fwhy-doesnt-uint-have-a-todouble%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is UInt not considered a number type?
Yes, it doesn't extend Number
class.
Declaration of Int
:
class Int : Number, Comparable<Int>
Declaration of UInt
:
inline class UInt : Comparable<UInt>
Starting with Kotlin version 1.3.30 UInt
has toFloat
and toDouble
methods.
1
Thanks, that was surprising. Is there a way to convert aUInt
to aDouble
in some other way?
– Rakete1111
Apr 11 at 16:14
3
@Rakete1111 Trybar.toLong.toDouble()
– Andrew Churilo
Apr 11 at 16:18
add a comment |
Is UInt not considered a number type?
Yes, it doesn't extend Number
class.
Declaration of Int
:
class Int : Number, Comparable<Int>
Declaration of UInt
:
inline class UInt : Comparable<UInt>
Starting with Kotlin version 1.3.30 UInt
has toFloat
and toDouble
methods.
1
Thanks, that was surprising. Is there a way to convert aUInt
to aDouble
in some other way?
– Rakete1111
Apr 11 at 16:14
3
@Rakete1111 Trybar.toLong.toDouble()
– Andrew Churilo
Apr 11 at 16:18
add a comment |
Is UInt not considered a number type?
Yes, it doesn't extend Number
class.
Declaration of Int
:
class Int : Number, Comparable<Int>
Declaration of UInt
:
inline class UInt : Comparable<UInt>
Starting with Kotlin version 1.3.30 UInt
has toFloat
and toDouble
methods.
Is UInt not considered a number type?
Yes, it doesn't extend Number
class.
Declaration of Int
:
class Int : Number, Comparable<Int>
Declaration of UInt
:
inline class UInt : Comparable<UInt>
Starting with Kotlin version 1.3.30 UInt
has toFloat
and toDouble
methods.
edited Apr 13 at 9:13
answered Apr 11 at 16:12
Andrew ChuriloAndrew Churilo
1,428814
1,428814
1
Thanks, that was surprising. Is there a way to convert aUInt
to aDouble
in some other way?
– Rakete1111
Apr 11 at 16:14
3
@Rakete1111 Trybar.toLong.toDouble()
– Andrew Churilo
Apr 11 at 16:18
add a comment |
1
Thanks, that was surprising. Is there a way to convert aUInt
to aDouble
in some other way?
– Rakete1111
Apr 11 at 16:14
3
@Rakete1111 Trybar.toLong.toDouble()
– Andrew Churilo
Apr 11 at 16:18
1
1
Thanks, that was surprising. Is there a way to convert a
UInt
to a Double
in some other way?– Rakete1111
Apr 11 at 16:14
Thanks, that was surprising. Is there a way to convert a
UInt
to a Double
in some other way?– Rakete1111
Apr 11 at 16:14
3
3
@Rakete1111 Try
bar.toLong.toDouble()
– Andrew Churilo
Apr 11 at 16:18
@Rakete1111 Try
bar.toLong.toDouble()
– Andrew Churilo
Apr 11 at 16:18
add a comment |
This appears to be coming in 1.3.30, according to this YouTrack request.
1.3.30 was just recently tagged and appears to be releasing very shortly.
add a comment |
This appears to be coming in 1.3.30, according to this YouTrack request.
1.3.30 was just recently tagged and appears to be releasing very shortly.
add a comment |
This appears to be coming in 1.3.30, according to this YouTrack request.
1.3.30 was just recently tagged and appears to be releasing very shortly.
This appears to be coming in 1.3.30, according to this YouTrack request.
1.3.30 was just recently tagged and appears to be releasing very shortly.
edited Apr 11 at 16:40
Rakete1111
35.8k1086123
35.8k1086123
answered Apr 11 at 16:13
ToddTodd
19.6k74857
19.6k74857
add a comment |
add a comment |
Added support in latest version 1.3.30
.
This release (More) brings support for more operations for unsigned types and arrays of unsigned types that mirror those for regular number types:
fun main()
val u1 = 2_147_483_649u
val u2 = 4_000_000_000u
println(u1.toDouble())
println(minOf(u1, u2))
val array: UIntArray = uintArrayOf(u1, u2)
println(array.max())
println(array.all it > Int.MAX_VALUE.toUInt() )
Note: UInt doesn't extend Number class.
/**
* Converts this [UInt] value to [Double].
*
* The resulting `Double` value represents the same numerical value as this `UInt`.
*/
@kotlin.internal.InlineOnly
public inline fun toDouble(): Double = uintToDouble(data)
add a comment |
Added support in latest version 1.3.30
.
This release (More) brings support for more operations for unsigned types and arrays of unsigned types that mirror those for regular number types:
fun main()
val u1 = 2_147_483_649u
val u2 = 4_000_000_000u
println(u1.toDouble())
println(minOf(u1, u2))
val array: UIntArray = uintArrayOf(u1, u2)
println(array.max())
println(array.all it > Int.MAX_VALUE.toUInt() )
Note: UInt doesn't extend Number class.
/**
* Converts this [UInt] value to [Double].
*
* The resulting `Double` value represents the same numerical value as this `UInt`.
*/
@kotlin.internal.InlineOnly
public inline fun toDouble(): Double = uintToDouble(data)
add a comment |
Added support in latest version 1.3.30
.
This release (More) brings support for more operations for unsigned types and arrays of unsigned types that mirror those for regular number types:
fun main()
val u1 = 2_147_483_649u
val u2 = 4_000_000_000u
println(u1.toDouble())
println(minOf(u1, u2))
val array: UIntArray = uintArrayOf(u1, u2)
println(array.max())
println(array.all it > Int.MAX_VALUE.toUInt() )
Note: UInt doesn't extend Number class.
/**
* Converts this [UInt] value to [Double].
*
* The resulting `Double` value represents the same numerical value as this `UInt`.
*/
@kotlin.internal.InlineOnly
public inline fun toDouble(): Double = uintToDouble(data)
Added support in latest version 1.3.30
.
This release (More) brings support for more operations for unsigned types and arrays of unsigned types that mirror those for regular number types:
fun main()
val u1 = 2_147_483_649u
val u2 = 4_000_000_000u
println(u1.toDouble())
println(minOf(u1, u2))
val array: UIntArray = uintArrayOf(u1, u2)
println(array.max())
println(array.all it > Int.MAX_VALUE.toUInt() )
Note: UInt doesn't extend Number class.
/**
* Converts this [UInt] value to [Double].
*
* The resulting `Double` value represents the same numerical value as this `UInt`.
*/
@kotlin.internal.InlineOnly
public inline fun toDouble(): Double = uintToDouble(data)
edited Apr 12 at 10:09
answered Apr 12 at 10:01
youngyoung
1,39621127
1,39621127
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55636856%2fwhy-doesnt-uint-have-a-todouble%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
possibly related: some architectures (notably x86) don't have native machine instructions to convert unsigned integers to floating point, only signed. (AVX512 finally adds that for x86, but it's still not widely available and very far from becoming baseline). Zero-extending to a wider signed integer type is by far the easiest implementation of unsigned->float or double when that's possible, but for 64-bit unsigned integers you need special tricks. Maybe Kotlin wanted to avoid that? But given that it runs on top of JVM or Javascript, maybe something else.
– Peter Cordes
Apr 12 at 3:43
@PeterCordes I doubt that any language would want to restrict itself to a single architecture's shortcomings. I mean even C allows this :) But interesting info nonetheless, thanks.
– Rakete1111
Apr 12 at 7:41