mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
add log2(x [,eps]) builtin function
Added log2(x [,eps]) builtin function. When x is an integer power of 2, log2(x) will return an integer, otherwise it will return the equivalent of ln(x)/ln(2).
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* regress - calc regression and correctness test suite
|
||||
*
|
||||
* Copyright (C) 1999-2017,2021 David I. Bell and Landon Curt Noll
|
||||
* Copyright (C) 1999-2017,2021,2023 David I. Bell and Landon Curt Noll
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
@@ -2997,6 +2997,45 @@ define test_2600()
|
||||
strcat(str(tnum++),
|
||||
': round(log(1.2+1.2i,1e-10),10) == ',
|
||||
'0.2296962439+0.3410940885i'));
|
||||
vrfy(log2(2) == 1,
|
||||
strcat(str(tnum++), ': log2(2) == 1'));
|
||||
vrfy(log2(4) == 2,
|
||||
strcat(str(tnum++), ': log2(4) == 2'));
|
||||
vrfy(log2(1024) == 10,
|
||||
strcat(str(tnum++), ': log2(1024) == 10'));
|
||||
vrfy(log2(2^500) == 500,
|
||||
strcat(str(tnum++), ': log2(2^500) == 500'));
|
||||
vrfy(log2(1/2^23209) == -23209,
|
||||
strcat(str(tnum++), ': log2(1/2^23209) == -23209'));
|
||||
vrfy(isint(log2(1/2^23209)),
|
||||
strcat(str(tnum++), ': isint(log2(1/2^23209))'));
|
||||
vrfy(round(log2(127),10) == 6.9886846868,
|
||||
strcat(str(tnum++),
|
||||
': round(log2(127),10) == 6.9886846868'));
|
||||
vrfy(round(log2(23209),10) == 14.5023967426,
|
||||
strcat(str(tnum++),
|
||||
': round(log2(23209),10) == 14.5023967426'));
|
||||
vrfy(round(log2(2^17-19),10) == 16.9997908539,
|
||||
strcat(str(tnum++),
|
||||
': round(log2(2^17-19),10) == 16.9997908539'));
|
||||
vrfy(round(log2(-127),10) == 6.9886846868+4.5323601418i,
|
||||
strcat(str(tnum++),
|
||||
': round(log2(-127),10) == 6.9886846868+4.5323601418i'));
|
||||
vrfy(round(log2(2+3i),10) == 1.8502198591+1.4178716307i,
|
||||
strcat(str(tnum++),
|
||||
': round(log2(2+3i),10) == 1.8502198591+1.4178716307i'));
|
||||
vrfy(round(log2(-2+3i),10) == 1.8502198591+3.1144885111i,
|
||||
strcat(str(tnum++),
|
||||
': round(log2(-2+3i),10) == 1.8502198591+3.1144885111i'));
|
||||
vrfy(round(log2(2-3i),10) == 1.8502198591-1.4178716307i,
|
||||
strcat(str(tnum++),
|
||||
': round(log2(2-3i),10) == 1.8502198591-1.4178716307i'));
|
||||
vrfy(round(log2(-2-3i),10) == 1.8502198591-3.1144885111i,
|
||||
strcat(str(tnum++),
|
||||
': round(log2(-2-3i),10) == 1.8502198591-3.1144885111i'));
|
||||
vrfy(round(log2(17+0.3i),10) == 4.0876874474+0.0254566819i,
|
||||
strcat(str(tnum++),
|
||||
': round(log2(17+0.3i),10) == 4.0876874474+0.0254566819i'));
|
||||
epsilon(i),;
|
||||
print tnum++: ': epsilon(i),;';
|
||||
|
||||
|
Reference in New Issue
Block a user