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. net.sf.json日期类型格式化输出

    net.sf.json 日期类型格式化输出 Date, Timestamp ; 编写工具类 package cn.jorcen.commons.util; import java.text.DateF ...

  2. 朴素贝叶斯文本分类java实现

    package com.data.ml.classify; import java.io.File; import java.util.ArrayList; import java.util.Coll ...

  3. CSS display 属性详解

    定义display 属性设置是否及如何显示元素. 继承性: No 说明 这个属性用于定义建立布局时元素生成的显示框类型.对于 HTML 等文档类型,如果使用 display 不 谨慎会很危险,因为可能 ...

  4. javascript-代码复用模式

    代码复用模式 1)使用原型继承            函数对象中自身声明的方法和属性与prototype声名的对象有什么不同:      自身声明的方法和属性是静态的, 也就是说你在声明后,试图再去增 ...

  5. android 自定义标题栏 titleBar自定义

    在value文件夹下添加style.xml <?xml version="1.0" encoding="utf-8"?> <resources ...

  6. 李洪强iOS开发本人集成环信的经验总结_01环信SDK的导入

    李洪强iOS开发本人集成环信的经验总结_01环信SDK的导入 01 - 直接在项目中导入SDK和一些静态库 这个时候,没有错误的编译没有错误的话,就说明SDK已经配置成功 还有一种方法是用cocoap ...

  7. freshStartTail 第一次启动时 抛弃旧的日志

    freshStartTail [on/off] (requires v8.18.0+) Default: off This is used to tell rsyslog to seek to the ...

  8. Form - 遍历行

    go_block('block_name'); first_record; LOOP   message(:block_name.item);   if :system.last_record  = ...

  9. hadoop2.2编程:从default mapreduce program 来理解mapreduce

    下面写一个default mapreduce 的程序: import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapr ...

  10. String对象不可改变的特性

    1. 声明String对象 String s = "abcd"; 图1 2. 将一个字符串变量赋值给另一个String变量 String s2 = s; 图2 3. 字符串连接 s ...