A Tour of Go Numeric Constants
2024-08-27 04:47:37
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);
最新文章
- iOS8新特性(1)-UIPopoverPresentationController使用
- lodop打印控件一点记录
- Android之Inflate()
- Java虚拟机学习记录
- JS图片加载失败显示默认图片
- Myeclipse 10 破解说明
- Ubuntu中安装DiscuzX2
- 看了看 #ifndef 和#pragma once 的区别
- [error] - Build path is incomplete. Cannot find class file for org/aspectj/weaver/refl
- adb.exe 已停止工作 解决
- 2018-04-10 我的GitHub诞生的日子,欢迎大家吐槽批评
- dbms_redefinition方式普通表改造分区表
- java 可设置最大内存
- Des加密解密算法java实现
- mysql 使用 GROUP BY 时报错 ERROR 1055 (42000)
- C++注入记事本
- CentOS 7 下 RabbitMQ 集群搭建
- xdoj-1324 (区间离散化-线段树求区间最值)
- HTML5将<;video>;视频设置为页面动态背景
- Problem A: 道路建设 解题报告
热门文章
- .net 添加不同项目框架引用出现的问题
- Viz World and Viz Curious Maps 教程 -- 基础篇
- centos 下查找软件安装在哪里的命令
- 查看linux系统的版本
- c++ 学习笔记 c++ 引用C库注意点:#ifdef __cplusplus 倒底是什么意思?
- linux如何安装jdk
- poj2411Mondriaan&#39;s Dream(状压)
- BZOJ_1625_ [Usaco2007_Dec]_宝石手镯_(01背包)
- zz-rtl8188eu的linux-usb-wifi调试及驱动编译150210
- (转载)四种常见的 POST 提交数据方式