Why does "Int" exist, but not "Float"?

user13507706

I saw that when using parse for example, you can do this: parse(Int, "123") (Int exists), but I can't do parse(Float, "12.3") (Float doesn't exist).

Why doesn't Float exist as well then? What is the difference between Int and for example Int64 or some other number after Int anyways (I know it has to do with the size, but how can you know when to use which)?

Oscar Smith

The reason for this is that machines are either 32 bit or 64 bit. This is the size of pointers on these machines, and since pointers are just integers in hardware, it is also the "natural" integer size. Floating point arithmetic is different. (Almost) all computers have both FLoat32 and Float64, and the choice needs to be made based on application (how much range and accuracy you need). That said, you could always define const Float = Float64 and then just use Float.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Why does a cast from int to float round the value?

分類Dev

Why does std::pow of a float and int invoke this overload?

分類Dev

Why does volatile exist?

分類Dev

Why does volatile exist?

分類Dev

Why is an addition of a float and int results a float?

分類Dev

Why forEach does not exist on NodeListOf

分類Dev

Laravel 2 instances of BadMethodCallException: 'int does not exist' and 'method does not exist'

分類Dev

Why doesn't my program work with float variables, but it does with int variables?

分類Dev

Why does state object exist in React?

分類Dev

Why does SQLite say that instr doesnt exist?

分類Dev

Why does postgres say operator does not exist: json ? unknown

分類Dev

Why use the 'int' data type instead of the 'float' data type?

分類Dev

What does error: invalid operands to binary % (have ‘float’ and ‘int’) mean

分類Dev

VS 2015 Update 2 - Variable does not exist when debugging, why?

分類Dev

Why does the "out" parameter exist in C# as a language construct?

分類Dev

Why does there exist many variations of the click event listener in jQuery?

分類Dev

Why does Nullable!(Nullable!int) refuse to compile?

分類Dev

Why does a FLOAT give me a more accurate result than a DECIMAL?

分類Dev

why does my float variable statement keeps on giving me an 'Cannot implicitly convert type double to float' error?

分類Dev

Why does mongoose model's hasOwnProperty return false when property does exist?

分類Dev

Why does python's bisect_left return a valid index even if the value does not exist?

分類Dev

format()int as float

分類Dev

memcpy ing float into int

分類Dev

why I get error when using int() function to convert float to integer?

分類Dev

Why does memcpy to int not work after calling memcpy to bool value

分類Dev

Why does Haskell ignore the hard coded int in this example?

分類Dev

Why does assembly use INT instruction when it can use CALL?

分類Dev

Why does coverity complain when using calloc with unsigned int

分類Dev

Animation getTexture() does not exist?

Related 関連記事

  1. 1

    Why does a cast from int to float round the value?

  2. 2

    Why does std::pow of a float and int invoke this overload?

  3. 3

    Why does volatile exist?

  4. 4

    Why does volatile exist?

  5. 5

    Why is an addition of a float and int results a float?

  6. 6

    Why forEach does not exist on NodeListOf

  7. 7

    Laravel 2 instances of BadMethodCallException: 'int does not exist' and 'method does not exist'

  8. 8

    Why doesn't my program work with float variables, but it does with int variables?

  9. 9

    Why does state object exist in React?

  10. 10

    Why does SQLite say that instr doesnt exist?

  11. 11

    Why does postgres say operator does not exist: json ? unknown

  12. 12

    Why use the 'int' data type instead of the 'float' data type?

  13. 13

    What does error: invalid operands to binary % (have ‘float’ and ‘int’) mean

  14. 14

    VS 2015 Update 2 - Variable does not exist when debugging, why?

  15. 15

    Why does the "out" parameter exist in C# as a language construct?

  16. 16

    Why does there exist many variations of the click event listener in jQuery?

  17. 17

    Why does Nullable!(Nullable!int) refuse to compile?

  18. 18

    Why does a FLOAT give me a more accurate result than a DECIMAL?

  19. 19

    why does my float variable statement keeps on giving me an 'Cannot implicitly convert type double to float' error?

  20. 20

    Why does mongoose model's hasOwnProperty return false when property does exist?

  21. 21

    Why does python's bisect_left return a valid index even if the value does not exist?

  22. 22

    format()int as float

  23. 23

    memcpy ing float into int

  24. 24

    why I get error when using int() function to convert float to integer?

  25. 25

    Why does memcpy to int not work after calling memcpy to bool value

  26. 26

    Why does Haskell ignore the hard coded int in this example?

  27. 27

    Why does assembly use INT instruction when it can use CALL?

  28. 28

    Why does coverity complain when using calloc with unsigned int

  29. 29

    Animation getTexture() does not exist?

ホットタグ

アーカイブ