Why doesn't UInt have a toDouble()? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag?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
What are 'alternative tunings' of a guitar and why would you use them? Doesn't it make it more difficult to play?
What is a Meta algorithm?
How do I determine if the rules for a long jump or high jump are applicable for Monks?
What does the "x" in "x86" represent?
If Jon Snow became King of the Seven Kingdoms what would his regnal number be?
Should I discuss the type of campaign with my players?
Do I really need recursive chmod to restrict access to a folder?
Why did the IBM 650 use bi-quinary?
List *all* the tuples!
What causes the vertical darker bands in my photo?
Is high blood pressure ever a symptom attributable solely to dehydration?
What makes black pepper strong or mild?
How to draw this diagram using TikZ package?
What would be the ideal power source for a cybernetic eye?
Should I use Javascript Classes or Apex Classes in Lightning Web Components?
Should I call the interviewer directly, if HR aren't responding?
Are my PIs rude or am I just being too sensitive?
Is it possible to boil a liquid by just mixing many immiscible liquids together?
Why are there no cargo aircraft with "flying wing" design?
How to assign captions for two tables in LaTeX?
The logistics of corpse disposal
When is phishing education going too far?
How can I make names more distinctive without making them longer?
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
Why doesn't UInt have a toDouble()?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?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.5k1085122
35.5k1085122
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 aUIntto aDoublein 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 aUIntto aDoublein 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 aUIntto aDoublein 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 2 days ago
answered Apr 11 at 16:12
Andrew ChuriloAndrew Churilo
1,397814
1,397814
1
Thanks, that was surprising. Is there a way to convert aUIntto aDoublein 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 aUIntto aDoublein 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.5k1085122
35.5k1085122
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