mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 21:38:33 +00:00
remove @TypeOf() hacks for comptime_int/comptime_float
This commit is contained in:
parent
508a8980ba
commit
2e5342512f
@ -21,7 +21,7 @@ pub fn ln(x: var) @TypeOf(x) {
|
||||
const T = @TypeOf(x);
|
||||
switch (@typeId(T)) {
|
||||
TypeId.ComptimeFloat => {
|
||||
return @TypeOf(1.0)(ln_64(x));
|
||||
return @as(comptime_float, ln_64(x));
|
||||
},
|
||||
TypeId.Float => {
|
||||
return switch (T) {
|
||||
@ -31,7 +31,7 @@ pub fn ln(x: var) @TypeOf(x) {
|
||||
};
|
||||
},
|
||||
TypeId.ComptimeInt => {
|
||||
return @TypeOf(1)(math.floor(ln_64(@as(f64, x))));
|
||||
return @as(comptime_int, math.floor(ln_64(@as(f64, x))));
|
||||
},
|
||||
TypeId.Int => {
|
||||
return @as(T, math.floor(ln_64(@as(f64, x))));
|
||||
|
||||
@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T {
|
||||
const float_base = math.lossyCast(f64, base);
|
||||
switch (@typeId(T)) {
|
||||
TypeId.ComptimeFloat => {
|
||||
return @TypeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base));
|
||||
return @as(comptime_float, math.ln(@as(f64, x)) / math.ln(float_base));
|
||||
},
|
||||
TypeId.ComptimeInt => {
|
||||
return @TypeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));
|
||||
return @as(comptime_int, math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));
|
||||
},
|
||||
builtin.TypeId.Int => {
|
||||
// TODO implement integer log without using float math
|
||||
|
||||
@ -22,7 +22,7 @@ pub fn log10(x: var) @TypeOf(x) {
|
||||
const T = @TypeOf(x);
|
||||
switch (@typeId(T)) {
|
||||
TypeId.ComptimeFloat => {
|
||||
return @TypeOf(1.0)(log10_64(x));
|
||||
return @as(comptime_float, log10_64(x));
|
||||
},
|
||||
TypeId.Float => {
|
||||
return switch (T) {
|
||||
@ -32,7 +32,7 @@ pub fn log10(x: var) @TypeOf(x) {
|
||||
};
|
||||
},
|
||||
TypeId.ComptimeInt => {
|
||||
return @TypeOf(1)(math.floor(log10_64(@as(f64, x))));
|
||||
return @as(comptime_int, math.floor(log10_64(@as(f64, x))));
|
||||
},
|
||||
TypeId.Int => {
|
||||
return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));
|
||||
|
||||
@ -22,7 +22,7 @@ pub fn log2(x: var) @TypeOf(x) {
|
||||
const T = @TypeOf(x);
|
||||
switch (@typeId(T)) {
|
||||
TypeId.ComptimeFloat => {
|
||||
return @TypeOf(1.0)(log2_64(x));
|
||||
return @as(comptime_float, log2_64(x));
|
||||
},
|
||||
TypeId.Float => {
|
||||
return switch (T) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user