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

A Tour of Go Numeric Constants的更多相关文章

  1. Vim编辑器Go简单入门

    今天是一次做Go的笔记,一开始直接打开Github上的Go项目然后跑到Wiki位置,然后作者列出了一堆学习Go的资料,这里我 以第一个学习资料https://tour.golang.org/作为Go学 ...

  2. peoplesoft SQR language

    Understanding SQR Data Elements !Variables!Variables are storage places for text or numbers that you ...

  3. HANA SQLScript

    数据类型 日期时间类型 DATE(日期) DATE 数据类型由年.月.日信息组成,表示一个日期值. DATA 类型的默认格式为‘YYYY-MM-DD’. YYYY 表示年, MM 表示月而 DD 表示 ...

  4. Shape comparison language

      形状比较语言, 九交模型 In this topic About shape comparison language Dimensionality Extensions to the CBM SC ...

  5. clean code meaningful names

    ---恢复内容开始--- Meaningful Names: use Intention-Revealing Names //nice,Everyone who reads your code (in ...

  6. 【NS2仿真】RTP协议安装

    来自: http://personales.upv.es/fboronat/Research/NS2_RTP/NS2_RTP_RTCP_module.htm 文件:http://pan.baidu.c ...

  7. leetcode Database3(Nth Highest Salary<—>Consecutive Numbers<—>Department Highest Salary)

    一.Nth Highest Salary Write a SQL query to get the nth highest salary from the Employee table. +----+ ...

  8. batch 数字进制的问题

    when set viable to number type in cmdexample: set /a num=0833echo %num% display: Invalid number.  Nu ...

  9. JVMInternals--reference

    This article explains the internal architecture of the Java Virtual Machine (JVM). The following dia ...

随机推荐

  1. Lucene基础(二)--索引的操作

    索引的操作 我们建立所有就是要达到快速检索的目的,对数据能够方面便的查找,和数据库类似,索引也有自己的相关增删改查的操作. 在索引的增删改查中,增删改属于写操作,主要是有IndexWrite提供的方法 ...

  2. eCos中断模型

    http://blog.csdn.net/chychc/article/details/8313458 http://www.cnblogs.com/RandyQ/archive/2013/04/14 ...

  3. 调试Android USB遇到的令人费解的问题

    上周参照网上代码,做了USB的初步探测程序,工作正常 .今天从硬件部拿到了一段例程,原本打算参考它来完善自己的程序.但运行之后总是报错,逐步跟进错误,进而发现了一个匪疑所思的问题.调试一天也未发现原因 ...

  4. yii 验证器和验证码

    http://www.yiiframework.com/doc/api/1.1/CCaptcha http://www.cnblogs.com/analyzer/articles/1673015.ht ...

  5. gcc编译常用选项

    我的博客:www.while0.com GDB调试: -g 生成的可执行文件才可以用gdb调试 (建议在发行版中用strip filename 来把这些调试信息去除) 开始调试. 以下是基础调试命令: ...

  6. mysql 有索引没走索引 更新锁全表

    Session 1: mysql> select connection_id(); +-----------------+ | connection_id() | +-------------- ...

  7. SQL Server 连接字符串和身份验证详解

    SQL Server .NET Data Provider 连接字符串包含一个由一些属性名/值对组成的集合.每一个属性/值对都由分号隔开.          PropertyName1=Value1; ...

  8. java常量池概念

    在class文件中,“常量池”是最复杂也最值得关注的内容. Java是一种动态连接的语言,常量池的作用非常重要,常量池中除了包含代码中所定义的各种基本类型(如int.long等等)和对象型(如Stri ...

  9. .NET(C#)调用webService获取客户端IP地址所属区域(非异步)

    功能描述: 此接口用于获取客户端访问的IP的地址所属的区域(国家,城市等).通过输入IP地址查询国家.城市.所有者等信息.没有注明国家的为中国输入参数:IP地址(自动替换 " ." ...

  10. Web服务器排行:Nginx超越Apache 成为全球

    Apache(34.5%)第一名的位置.不过,纵观全球,Apache仍然是最受欢迎的Web服务器,有65.3%的网站使用. 在排名前100万的网站中,主流服务器仍为Apache,占据了60.6%的份额 ...