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. ASP.NET MVC got 405 error on HTTP DELETE request

    使用Backload的时候在本地调试通过,上传服务器后出现405错误(监控通信时可以发现ajax的返回结果为405) 通过修改webconfig可以解决: <system.webServer&g ...

  2. ListView 长按拖动会变黑的解决方案

    在ListView的xml文件中添加这个属性: android:cacheColorHint="#00000000"

  3. 配置Pycharm3.4.1调试edX Devstack

    前提: 1.安装好Ubuntu 2.在Ubuntn上利用vagrant+VirtualBox 搭建好了edX Developer Stack,并能成功访问 3.在Ubuntu下安装好了Pycharm- ...

  4. 在Android手机上安装linux系统

    在anroid手机中安装fedora系统.记住不只是教你安装fedora系统. 需要的备注与软件 1.一个已经root的Android手机,记住是root后的,root后的,root后的.(重要的事情 ...

  5. 解决win8.1右键菜单出现在左边

    这个问题估计很少有人遇到,当在桌面上单击鼠标右键时,如果正常情况下,应该是在鼠标光标的右侧弹出来,除非右边的空间不够了,才在左侧弹出.但遇到故障,就是不论在桌面的哪里点右键,菜单都在左侧弹出,虽然不影 ...

  6. Android中改变dialog的显示的位置和大小

    private void setDialogSize(Dialog dg) { Window dialogWindow = dg.getWindow(); WindowManager.LayoutPa ...

  7. 测试ODBC与OLE

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data. ...

  8. java常量池概念

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

  9. Guid 的几种形式

    Guid.NewGuid().ToString()得几种格式显示 1.Guid.NewGuid().ToString("N") 结果为:       38bddf48f43c485 ...

  10. 【转】基本数据持久性(一) 使用plist保存和读取数据

    原文网址:http://www.it165.net/pro/html/201309/7170.html 想保存成绩.记录得分.保存账号密码等等?数据持久性可以做到这一点!这篇文章通过简单的程序,来分享 ...