Pikchr

Check-in [18ae3a4ab5]
Login
Overview
Comment:Fix the built-in abs() function so that it actually works. Add a test case.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 18ae3a4ab5c9bd8c1f212cab7cc0218fb97bfd7ae7f0072c72b9ce4ff015fcb6
User & Date: drh 2022-03-28 13:37:02.119
Context
2022-03-31
00:26
Typo fix in userman.md: s/three/five/ (check-in: 152e4c065c user: stephan tags: trunk)
2022-03-28
13:37
Fix the built-in abs() function so that it actually works. Add a test case. (check-in: 18ae3a4ab5 user: drh tags: trunk)
2022-01-30
21:43
Add links on the homepage to Zellyn Hunter's port of pikchr to Go. (check-in: 5db3aa1d29 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to pikchr.c.
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
}

/* Compute one of the built-in functions
*/
static PNum pik_func(Pik *p, PToken *pFunc, PNum x, PNum y){
  PNum v = 0.0;
  switch( pFunc->eCode ){
    case FN_ABS:  v = v<0.0 ? -v : v;  break;
    case FN_COS:  v = cos(x);          break;
    case FN_INT:  v = rint(x);         break;
    case FN_SIN:  v = sin(x);          break;
    case FN_SQRT:
      if( x<0.0 ){
        pik_error(p, pFunc, "sqrt of negative value");
        v = 0.0;







|







6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
}

/* Compute one of the built-in functions
*/
static PNum pik_func(Pik *p, PToken *pFunc, PNum x, PNum y){
  PNum v = 0.0;
  switch( pFunc->eCode ){
    case FN_ABS:  v = x<0.0 ? -x : x;  break;
    case FN_COS:  v = cos(x);          break;
    case FN_INT:  v = rint(x);         break;
    case FN_SIN:  v = sin(x);          break;
    case FN_SQRT:
      if( x<0.0 ){
        pik_error(p, pFunc, "sqrt of negative value");
        v = 0.0;
Changes to pikchr.y.
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
}

/* Compute one of the built-in functions
*/
static PNum pik_func(Pik *p, PToken *pFunc, PNum x, PNum y){
  PNum v = 0.0;
  switch( pFunc->eCode ){
    case FN_ABS:  v = v<0.0 ? -v : v;  break;
    case FN_COS:  v = cos(x);          break;
    case FN_INT:  v = rint(x);         break;
    case FN_SIN:  v = sin(x);          break;
    case FN_SQRT:
      if( x<0.0 ){
        pik_error(p, pFunc, "sqrt of negative value");
        v = 0.0;







|







4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
}

/* Compute one of the built-in functions
*/
static PNum pik_func(Pik *p, PToken *pFunc, PNum x, PNum y){
  PNum v = 0.0;
  switch( pFunc->eCode ){
    case FN_ABS:  v = x<0.0 ? -x : x;  break;
    case FN_COS:  v = cos(x);          break;
    case FN_INT:  v = rint(x);         break;
    case FN_SIN:  v = sin(x);          break;
    case FN_SQRT:
      if( x<0.0 ){
        pik_error(p, pFunc, "sqrt of negative value");
        v = 0.0;
Added tests/test76.pikchr.


















>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
box "Function test" width 5cm
pi = 3.1415926
print "abs(-10):",abs(-10)
print "cos(pi/3):",cos(pi/3)
print "int(18.5):",int(18.5)
print "max(5,-18.23):", max(5,-18.23)
print "min(5,-18.23):", min(5,-18.23)
print "sin(pi/6):",sin(pi/6)
print "sqrt(16):",sqrt(16)