1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

snake_case consts

This commit is contained in:
Alexander Medvednikov
2019-10-12 22:31:05 +03:00
parent 81f8b26127
commit a76165828b
17 changed files with 124 additions and 125 deletions

View File

@@ -9,36 +9,36 @@ module math
// All functions are sorted alphabetically.
const (
E = 2.71828182845904523536028747135266249775724709369995957496696763
Pi = 3.14159265358979323846264338327950288419716939937510582097494459
Phi = 1.61803398874989484820458683436563811772030917980576286213544862
Tau = 6.28318530717958647692528676655900576839433879875021164194988918
e = 2.71828182845904523536028747135266249775724709369995957496696763
pi = 3.14159265358979323846264338327950288419716939937510582097494459
phi = 1.61803398874989484820458683436563811772030917980576286213544862
tau = 6.28318530717958647692528676655900576839433879875021164194988918
Sqrt2 = 1.41421356237309504880168872420969807856967187537694807317667974
SqrtE = 1.64872127070012814684865078781416357165377610071014801157507931
SqrtPi = 1.77245385090551602729816748334114518279754945612238712821380779
SqrtTau = 2.50662827463100050241576528481104525300698674060993831662992357
SqrtPhi = 1.27201964951406896425242246173749149171560804184009624861664038
sqrt2 = 1.41421356237309504880168872420969807856967187537694807317667974
sqrt_e = 1.64872127070012814684865078781416357165377610071014801157507931
sqrt_pi = 1.77245385090551602729816748334114518279754945612238712821380779
sqrt_tau = 2.50662827463100050241576528481104525300698674060993831662992357
sqrt_phi = 1.27201964951406896425242246173749149171560804184009624861664038
Ln2 = 0.693147180559945309417232121458176568075500134360255254120680009
Log2E = 1.0 / Ln2
Ln10 = 2.30258509299404568401799145468436420760110148862877297603332790
Log10E = 1.0 / Ln10
ln2 = 0.693147180559945309417232121458176568075500134360255254120680009
log2_e = 1.0 / ln2
ln10 = 2.30258509299404568401799145468436420760110148862877297603332790
log10_e = 1.0 / ln10
)
const (
MaxI8 = 127
MinI8 = -128
MaxI16 = 32767
MinI16 = -32768
MaxI32 = 2147483647
MinI32 = -2147483648
max_i8 = 127
min_i8 = -128
max_i16 = 32767
min_i16 = -32768
max_i32 = 2147483647
min_i32 = -2147483648
// MaxI64 = ((1<<63) - 1)
// MinI64 = (-(1 << 63) )
MaxU8 = 255
MaxU16 = 65535
MaxU32 = 4294967295
MaxU64 = 18446744073709551615
max_u8 = 255
max_u16 = 65535
max_u32 = 4294967295
max_u64 = 18446744073709551615
)
// Returns the absolute value.
@@ -93,7 +93,7 @@ pub fn cosh(a f64) f64 {
// degrees convert from degrees to radians.
pub fn degrees(radians f64) f64 {
return radians * (180.0 / Pi)
return radians * (180.0 / pi)
}
// exp calculates exponent of the number (math.pow(math.E, a)).
@@ -277,7 +277,7 @@ pub fn pow(a, b f64) f64 {
// radians convert from radians to degrees.
pub fn radians(degrees f64) f64 {
return degrees * (Pi / 180.0)
return degrees * (pi / 180.0)
}
// round returns the integer nearest to the provided value.

View File

@@ -485,7 +485,7 @@ pub fn dir(path string) string {
if path == '.' {
return getwd()
}
pos := path.last_index(PathSeparator)
pos := path.last_index(path_separator)
if pos == -1 {
return '.'
}
@@ -502,7 +502,7 @@ fn path_sans_ext(path string) string {
pub fn basedir(path string) string {
pos := path.last_index(PathSeparator)
pos := path.last_index(path_separator)
if pos == -1 {
return path
}
@@ -510,7 +510,7 @@ pub fn basedir(path string) string {
}
pub fn filename(path string) string {
return path.all_after(PathSeparator)
return path.all_after(path_separator)
}
// get_line returns a one-line string from stdin
@@ -626,7 +626,7 @@ pub fn home_dir() string {
}
home += homepath
}
home += PathSeparator
home += path_separator
return home
}
@@ -795,7 +795,7 @@ pub fn walk_ext(path, ext string) []string {
if file.starts_with('.') {
continue
}
p := path + PathSeparator + file
p := path + path_separator + file
if os.is_dir(p) {
res << walk_ext(p, ext)
}
@@ -859,9 +859,9 @@ pub fn print_backtrace() {
}
pub fn mkdir_all(path string) {
mut p := if path.starts_with(os.PathSeparator) { os.PathSeparator } else { '' }
for subdir in path.split(os.PathSeparator) {
p += subdir + os.PathSeparator
mut p := if path.starts_with(os.path_separator) { os.path_separator } else { '' }
for subdir in path.split(os.path_separator) {
p += subdir + os.path_separator
if !os.dir_exists(p) {
os.mkdir(p)
}

View File

@@ -4,7 +4,6 @@ module os
#include <unistd.h>
const (
PathSeparator = '/'
path_separator = '/'
)

View File

@@ -4,7 +4,6 @@ module os
#include <winsock2.h>
const (
PathSeparator = '\\'
path_separator = '\\'
)

View File

@@ -7,7 +7,7 @@ module time
import rand
const (
MonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
)
#include <time.h>
@@ -60,17 +60,17 @@ const (
// The unsigned zero year for internal calculations.
// Must be 1 mod 400, and times before it will not compute correctly,
// but otherwise can be changed at will.
absoluteZeroYear = i64(-292277022399)
absolute_zero_year = i64(-292277022399)
secondsPerMinute = 60
secondsPerHour = 60 * secondsPerMinute
secondsPerDay = 24 * secondsPerHour
secondsPerWeek = 7 * secondsPerDay
daysPer400Years = 365*400 + 97
daysPer100Years = 365*100 + 24
daysPer4Years = 365*4 + 1
seconds_per_minute = 60
seconds_per_hour = 60 * seconds_per_minute
seconds_per_day = 24 * seconds_per_hour
seconds_per_week = 7 * seconds_per_day
days_per_400_years = 365*400 + 97
days_per_100_years = 365*100 + 24
days_per_4_years = 365*4 + 1
daysBefore = [
days_before = [
0,
31,
31 + 28,
@@ -88,33 +88,38 @@ const (
)
const (
months_string = 'JanFebMarAprMayJunJulAugSepOctNovDec'
days_string = 'MonTueWedThuFriSatSun'
)
// Based on Go's time package.
// Copyright 2009 The Go Authors.
pub fn unix(abs int) Time {
// Split into time and day.
mut d := abs / secondsPerDay
mut d := abs / seconds_per_day
// Account for 400 year cycles.
mut n := d / daysPer400Years
mut n := d / days_per_400_years
mut y := 400 * n
d -= daysPer400Years * n
d -= days_per_400_years * n
// Cut off 100-year cycles.
// The last cycle has one extra leap year, so on the last day
// of that year, day / daysPer100Years will be 4 instead of 3.
// of that year, day / days_per_100_years will be 4 instead of 3.
// Cut it back down to 3 by subtracting n>>2.
n = d / daysPer100Years
n = d / days_per_100_years
n -= n >> 2
y += 100 * n
d -= daysPer100Years * n
d -= days_per_100_years * n
// Cut off 4-year cycles.
// The last cycle has a missing leap year, which does not
// affect the computation.
n = d / daysPer4Years
n = d / days_per_4_years
y += 4 * n
d -= daysPer4Years * n
d -= days_per_4_years * n
// Cut off years within a 4-year cycle.
// The last year is a leap year, so on the last day of that year,
@@ -128,10 +133,10 @@ pub fn unix(abs int) Time {
yday := int(d)
mut day := yday
year := abs / int(3.154e+7) + 1970 //int(i64(y) + absoluteZeroYear)
hour := int(abs%secondsPerDay) / secondsPerHour
minute := int(abs % secondsPerHour) / secondsPerMinute
second := int(abs % secondsPerMinute)
year := abs / int(3.154e+7) + 1970 //int(i64(y) + absolute_zero_year)
hour := int(abs%seconds_per_day) / seconds_per_hour
minute := int(abs % seconds_per_hour) / seconds_per_minute
second := int(abs % seconds_per_minute)
if is_leap_year(year) {
// Leap year
@@ -149,12 +154,12 @@ pub fn unix(abs int) Time {
// The estimate may be too low by at most one month, so adjust.
mut month := day / 31
mut begin := 0
end := int(daysBefore[month+1])
end := int(days_before[month+1])
if day >= end {
month++
begin = end
} else {
begin = int(daysBefore[month])
begin = int(days_before[month])
}
month++ // because January is 1
@@ -182,14 +187,10 @@ pub fn (t Time) format() string {
return '${t.year}-${t.month:02d}-${t.day:02d} ${t.hour:02d}:${t.minute:02d}'
}
const (
Months = 'JanFebMarAprMayJunJulAugSepOctNovDec'
Days = 'MonTueWedThuFriSatSun'
)
pub fn (t Time) smonth() string {
i := t.month - 1
return Months.substr(i * 3, (i + 1) * 3)
return months_string.substr(i * 3, (i + 1) * 3)
}
// 21:04
@@ -386,7 +387,7 @@ pub fn (t Time) day_of_week() int {
// weekday_str() returns the current day in string (upto 3 characters)
pub fn (t Time) weekday_str() string {
i := t.day_of_week() - 1
return Days.substr(i * 3, (i + 1) * 3)
return days_string.substr(i * 3, (i + 1) * 3)
}
struct C.timeval {
@@ -450,6 +451,6 @@ pub fn days_in_month(month, year int) ?int {
return error('Invalid month: $month')
}
extra := if month == 2 && is_leap_year(year) {1} else {0}
res := MonthDays[month-1] + extra
res := month_days[month-1] + extra
return res
}