Numeric constants are high-precision values.

An untyped constant takes the type needed by its context.

Try printing needInt(Big) too.

package main 

import "fmt"

const (
Big = <<
Small = Big >>
) func needInt(x int) int {
return x* +
} func needFloat(x float64) float64{
return x * 0.1
} func main() {
fmt.Println(needInt(Small))
fmt.Println(needFloat(Small))
fmt.Println(needFloat(Big))
}
package main 

import "fmt"

const (
Big = <<
Small = Big >>
) func needInt(x int) int {
return x* +
} func needFloat(x float64) float64{
return x * 0.1
} func main() {
fmt.Println(Small);
var intVariable int =
//var float32Variable float32 = 1.2
fmt.Println(needInt(Small))
// constant 1267650600228229401496703205376 overflows int
//fmt.Println(needInt(Big))
fmt.Println(needFloat(Small))
fmt.Println(needFloat(Big)) //go语言对类型的要求是很严格的,所以你不能传递int到float中或者float到int
fmt.Println(needInt(intVariable))
//cannot use float32Variable (type float32) as type int in argument to needInt
//fmt.Println(needInt(float32Variable))
//cannot use intVariable (type int) as type float64 in argument to needFloat
//fmt.Println(needFloat(intVariable))
//cannot use float32Variable (type float32) as type float64 in argument to needFloat
//fmt.Println(needFloat(float32Variable)) }

不过常量却相对宽容一些

    //constant 1267650600228229401496703205376 overflows int
fmt.Println(Big);

最新文章

  1. iOS8新特性(1)-UIPopoverPresentationController使用
  2. lodop打印控件一点记录
  3. Android之Inflate()
  4. Java虚拟机学习记录
  5. JS图片加载失败显示默认图片
  6. Myeclipse 10 破解说明
  7. Ubuntu中安装DiscuzX2
  8. 看了看 #ifndef 和#pragma once 的区别
  9. [error] - Build path is incomplete. Cannot find class file for org/aspectj/weaver/refl
  10. adb.exe 已停止工作 解决
  11. 2018-04-10 我的GitHub诞生的日子,欢迎大家吐槽批评
  12. dbms_redefinition方式普通表改造分区表
  13. java 可设置最大内存
  14. Des加密解密算法java实现
  15. mysql 使用 GROUP BY 时报错 ERROR 1055 (42000)
  16. C++注入记事本
  17. CentOS 7 下 RabbitMQ 集群搭建
  18. xdoj-1324 (区间离散化-线段树求区间最值)
  19. HTML5将&lt;video&gt;视频设置为页面动态背景
  20. Problem A: 道路建设 解题报告

热门文章

  1. .net 添加不同项目框架引用出现的问题
  2. Viz World and Viz Curious Maps 教程 -- 基础篇
  3. centos 下查找软件安装在哪里的命令
  4. 查看linux系统的版本
  5. c++ 学习笔记 c++ 引用C库注意点:#ifdef __cplusplus 倒底是什么意思?
  6. linux如何安装jdk
  7. poj2411Mondriaan&#39;s Dream(状压)
  8. BZOJ_1625_ [Usaco2007_Dec]_宝石手镯_(01背包)
  9. zz-rtl8188eu的linux-usb-wifi调试及驱动编译150210
  10. (转载)四种常见的 POST 提交数据方式