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;








27















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?










share|improve this question






















  • 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

















27















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?










share|improve this question






















  • 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













27












27








27








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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

















  • 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












3 Answers
3






active

oldest

votes


















15















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.






share|improve this answer




















  • 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






  • 3





    @Rakete1111 Try bar.toLong.toDouble()

    – Andrew Churilo
    Apr 11 at 16:18


















19














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.






share|improve this answer
































    1














    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)





    share|improve this answer

























      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
      );



      );













      draft saved

      draft discarded


















      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









      15















      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.






      share|improve this answer




















      • 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






      • 3





        @Rakete1111 Try bar.toLong.toDouble()

        – Andrew Churilo
        Apr 11 at 16:18















      15















      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.






      share|improve this answer




















      • 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






      • 3





        @Rakete1111 Try bar.toLong.toDouble()

        – Andrew Churilo
        Apr 11 at 16:18













      15












      15








      15








      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.






      share|improve this answer
















      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.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      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 a UInt to a Double in some other way?

        – Rakete1111
        Apr 11 at 16:14






      • 3





        @Rakete1111 Try bar.toLong.toDouble()

        – Andrew Churilo
        Apr 11 at 16:18












      • 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






      • 3





        @Rakete1111 Try bar.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













      19














      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.






      share|improve this answer





























        19














        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.






        share|improve this answer



























          19












          19








          19







          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.






          share|improve this answer















          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 11 at 16:40









          Rakete1111

          35.8k1086123




          35.8k1086123










          answered Apr 11 at 16:13









          ToddTodd

          19.6k74857




          19.6k74857





















              1














              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)





              share|improve this answer





























                1














                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)





                share|improve this answer



























                  1












                  1








                  1







                  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)





                  share|improve this answer















                  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)






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 12 at 10:09

























                  answered Apr 12 at 10:01









                  youngyoung

                  1,39621127




                  1,39621127



























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      រឿង រ៉ូមេអូ និង ហ្ស៊ុយលីយេ សង្ខេបរឿង តួអង្គ បញ្ជីណែនាំ

                      Crop image to path created in TikZ? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Crop an inserted image?TikZ pictures does not appear in posterImage behind and beyond crop marks?Tikz picture as large as possible on A4 PageTransparency vs image compression dilemmaHow to crop background from image automatically?Image does not cropTikzexternal capturing crop marks when externalizing pgfplots?How to include image path that contains a dollar signCrop image with left size given

                      QGIS export composer to PDF scale the map [closed] Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Print Composer QGIS 2.6, how to export image?QGIS 2.8.1 print composer won't export all OpenCycleMap base layer tilesSave Print/Map QGIS composer view as PNG/PDF using Python (without changing anything in visible layout)?Export QGIS Print Composer PDF with searchable text labelsQGIS Print Composer does not change from landscape to portrait orientation?How can I avoid map size and scale changes in print composer?Fuzzy PDF export in QGIS running on macSierra OSExport the legend into its 100% size using Print ComposerScale-dependent rendering in QGIS PDF output