WeixiangYan/CodeTransOcean huggingface dataset:
Task: String matching



C#: class Program
{
	public static void Main (string[] args)
	{
		var value = "abcd".StartsWith("ab");
		value = "abcd".EndsWith("zn"); 
		value = "abab".Contains("bb"); 
		value = "abab".Contains("ab"); 
		int loc = "abab".IndexOf("bb"); 
		loc = "abab".IndexOf("ab"); 
		loc = "abab".IndexOf("ab",loc+1); 
	}
}
Task: String matching


C++: #include <string>
using namespace std;

string s1="abcd";
string s2="abab";
string s3="ab";

s1.compare(0,s3.size(),s3)==0;

s1.compare(s1.size()-s3.size(),s3.size(),s3)==0;

s1.find(s2)
int loc=s2.find(s3)
loc=s2.find(s3,loc+1)
Task: String matching





Java: "abcd".startsWith("ab") 
"abcd".endsWith("zn") 
"abab".contains("bb") 
"abab".contains("ab") 
int loc = "abab".indexOf("bb") 
loc = "abab".indexOf("ab") 
loc = "abab".indexOf("ab",loc+1)
Task: String matching







Python: "abcd".startswith("ab") 
"abcd".endswith("zn") 
"bb" in "abab" 
"ab" in "abab" 
loc = "abab".find("bb") 
loc = "abab".find("ab") 
loc = "abab".find("ab",loc+1)
Task: String matching








VB: Public Sub string_matching()
    word = "the"                                        
    sentence = "the last thing the man said was the"
    
     
    
    If InStr(1, sentence, word) = 1 Then
        Debug.Print "yes(1)"
    End If
    
    If Len(sentence) >= Len(word) _
        And Mid(sentence, 1, Len(word)) = word Then
        Debug.Print "yes(2)"
    End If
    
    If Len(sentence) >= Len(word) _
        And Mid(sentence, Len(sentence) - Len(word) + 1, Len(word)) = word Then
        Debug.Print "yes(3)"
    End If
    
    If Len(sentence) >= Len(word) _
    And InStr(Len(sentence) - Len(word) + 1, sentence, word) Then
        Debug.Print "yes(4)"
    End If
    
    r = InStr(1, sentence, word)
    Do While r <> 0
        Debug.Print r
        r = InStr(r + 1, sentence, word)
    Loop
End Sub
Task: String matching




Go: package main

import (
    "fmt"
    "strings"
)

func match(first, second string) {
    fmt.Printf("1. %s starts with %s: %t\n",
        first, second, strings.HasPrefix(first, second))
    i := strings.Index(first, second)
    fmt.Printf("2. %s contains %s: %t,\n", first, second, i >= 0)
    if i >= 0 {
        fmt.Printf("2.1. at location %d,\n", i)
        for start := i+1;; {
            if i = strings.Index(first[start:], second); i < 0 {
                break
            }
            fmt.Printf("2.2. at location %d,\n", start+i)
            start += i+1
        }
        fmt.Println("2.2. and that's all")
    }
    fmt.Printf("3. %s ends with %s: %t\n",
        first, second, strings.HasSuffix(first, second))
}

func main() {
    match("abracadabra", "abr")
}
Task: String matching



C#: class Program
{
	public static void Main (string[] args)
	{
		var value = "abcd".StartsWith("ab");
		value = "abcd".EndsWith("zn"); 
		value = "abab".Contains("bb"); 
		value = "abab".Contains("ab"); 
		int loc = "abab".IndexOf("bb"); 
		loc = "abab".IndexOf("ab"); 
		loc = "abab".IndexOf("ab",loc+1); 
	}
}








Fortran:       SUBROUTINE STARTS(A,B)	
       CHARACTER*(*) A,B
        IF (INDEX(A,B).EQ.1) THEN	
          WRITE (6,*) ">",A,"< starts with >",B,"<"
         ELSE
          WRITE (6,*) ">",A,"< does not start with >",B,"<"
        END IF
      END SUBROUTINE STARTS

      SUBROUTINE HAS(A,B)	
       CHARACTER*(*) A,B
       INTEGER L
        L = INDEX(A,B)		
        IF (L.LE.0) THEN
          WRITE (6,*) ">",A,"< does not contain >",B,"<"
         ELSE
          WRITE (6,*) ">",A,"< contains a >",B,"<, offset",L
        END IF
      END SUBROUTINE HAS

      SUBROUTINE ENDS(A,B)	
       CHARACTER*(*) A,B
       INTEGER L
        L = LEN(A) - LEN(B)	
        IF (L.LT.0) THEN	
          WRITE (6,*) ">",A,"< is too short to end with >",B,"<"	
        ELSE IF (A(L + 1:L + LEN(B)).NE.B) THEN	
          WRITE (6,*) ">",A,"< does not end with >",B,"<"
        ELSE
          WRITE (6,*) ">",A,"< ends with >",B,"<"
        END IF
      END SUBROUTINE ENDS

      CALL STARTS("This","is")
      CALL STARTS("Theory","The")
      CALL HAS("Bananas","an")
      CALL ENDS("Banana","an")
      CALL ENDS("Banana","na")
      CALL ENDS("Brief","Much longer")
      END
Task: String matching


C++: #include <string>
using namespace std;

string s1="abcd";
string s2="abab";
string s3="ab";

s1.compare(0,s3.size(),s3)==0;

s1.compare(s1.size()-s3.size(),s3.size(),s3)==0;

s1.find(s2)
int loc=s2.find(s3)
loc=s2.find(s3,loc+1)









Fortran:       SUBROUTINE STARTS(A,B)	
       CHARACTER*(*) A,B
        IF (INDEX(A,B).EQ.1) THEN	
          WRITE (6,*) ">",A,"< starts with >",B,"<"
         ELSE
          WRITE (6,*) ">",A,"< does not start with >",B,"<"
        END IF
      END SUBROUTINE STARTS

      SUBROUTINE HAS(A,B)	
       CHARACTER*(*) A,B
       INTEGER L
        L = INDEX(A,B)		
        IF (L.LE.0) THEN
          WRITE (6,*) ">",A,"< does not contain >",B,"<"
         ELSE
          WRITE (6,*) ">",A,"< contains a >",B,"<, offset",L
        END IF
      END SUBROUTINE HAS

      SUBROUTINE ENDS(A,B)	
       CHARACTER*(*) A,B
       INTEGER L
        L = LEN(A) - LEN(B)	
        IF (L.LT.0) THEN	
          WRITE (6,*) ">",A,"< is too short to end with >",B,"<"	
        ELSE IF (A(L + 1:L + LEN(B)).NE.B) THEN	
          WRITE (6,*) ">",A,"< does not end with >",B,"<"
        ELSE
          WRITE (6,*) ">",A,"< ends with >",B,"<"
        END IF
      END SUBROUTINE ENDS

      CALL STARTS("This","is")
      CALL STARTS("Theory","The")
      CALL HAS("Bananas","an")
      CALL ENDS("Banana","an")
      CALL ENDS("Banana","na")
      CALL ENDS("Brief","Much longer")
      END
Task: String matching

C: #include <string.h>
#include <stdio.h>

int startsWith(const char* container, const char* target)
{
  size_t clen = strlen(container), tlen = strlen(target);
  if (clen < tlen)
    return 0;
  return strncmp(container, target, tlen) == 0;
}

int endsWith(const char* container, const char* target)
{
  size_t clen = strlen(container), tlen = strlen(target);
  if (clen < tlen)
    return 0;
  return strncmp(container + clen - tlen, target, tlen) == 0;
}

int doesContain(const char* container, const char* target)
{
  return strstr(container, target) != 0;
}

int main(void)
{
  printf("Starts with Test ( Hello,Hell ) : %d\n", startsWith("Hello","Hell"));
  printf("Ends with Test ( Code,ode ) : %d\n", endsWith("Code","ode"));
  printf("Contains Test ( Google,msn ) : %d\n", doesContain("Google","msn"));

  return 0;
}










Fortran:       SUBROUTINE STARTS(A,B)	
       CHARACTER*(*) A,B
        IF (INDEX(A,B).EQ.1) THEN	
          WRITE (6,*) ">",A,"< starts with >",B,"<"
         ELSE
          WRITE (6,*) ">",A,"< does not start with >",B,"<"
        END IF
      END SUBROUTINE STARTS

      SUBROUTINE HAS(A,B)	
       CHARACTER*(*) A,B
       INTEGER L
        L = INDEX(A,B)		
        IF (L.LE.0) THEN
          WRITE (6,*) ">",A,"< does not contain >",B,"<"
         ELSE
          WRITE (6,*) ">",A,"< contains a >",B,"<, offset",L
        END IF
      END SUBROUTINE HAS

      SUBROUTINE ENDS(A,B)	
       CHARACTER*(*) A,B
       INTEGER L
        L = LEN(A) - LEN(B)	
        IF (L.LT.0) THEN	
          WRITE (6,*) ">",A,"< is too short to end with >",B,"<"	
        ELSE IF (A(L + 1:L + LEN(B)).NE.B) THEN	
          WRITE (6,*) ">",A,"< does not end with >",B,"<"
        ELSE
          WRITE (6,*) ">",A,"< ends with >",B,"<"
        END IF
      END SUBROUTINE ENDS

      CALL STARTS("This","is")
      CALL STARTS("Theory","The")
      CALL HAS("Bananas","an")
      CALL ENDS("Banana","an")
      CALL ENDS("Banana","na")
      CALL ENDS("Brief","Much longer")
      END
Task: String matching





Java: "abcd".startsWith("ab") 
"abcd".endsWith("zn") 
"abab".contains("bb") 
"abab".contains("ab") 
int loc = "abab".indexOf("bb") 
loc = "abab".indexOf("ab") 
loc = "abab".indexOf("ab",loc+1) 






Fortran:       SUBROUTINE STARTS(A,B)	
       CHARACTER*(*) A,B
        IF (INDEX(A,B).EQ.1) THEN	
          WRITE (6,*) ">",A,"< starts with >",B,"<"
         ELSE
          WRITE (6,*) ">",A,"< does not start with >",B,"<"
        END IF
      END SUBROUTINE STARTS

      SUBROUTINE HAS(A,B)	
       CHARACTER*(*) A,B
       INTEGER L
        L = INDEX(A,B)		
        IF (L.LE.0) THEN
          WRITE (6,*) ">",A,"< does not contain >",B,"<"
         ELSE
          WRITE (6,*) ">",A,"< contains a >",B,"<, offset",L
        END IF
      END SUBROUTINE HAS

      SUBROUTINE ENDS(A,B)	
       CHARACTER*(*) A,B
       INTEGER L
        L = LEN(A) - LEN(B)	
        IF (L.LT.0) THEN	
          WRITE (6,*) ">",A,"< is too short to end with >",B,"<"	
        ELSE IF (A(L + 1:L + LEN(B)).NE.B) THEN	
          WRITE (6,*) ">",A,"< does not end with >",B,"<"
        ELSE
          WRITE (6,*) ">",A,"< ends with >",B,"<"
        END IF
      END SUBROUTINE ENDS

      CALL STARTS("This","is")
      CALL STARTS("Theory","The")
      CALL HAS("Bananas","an")
      CALL ENDS("Banana","an")
      CALL ENDS("Banana","na")
      CALL ENDS("Brief","Much longer")
      END
Task: String matching







Python: "abcd".startswith("ab") 
"abcd".endswith("zn") 
"bb" in "abab" 
"ab" in "abab" 
loc = "abab".find("bb") 
loc = "abab".find("ab") 
loc = "abab".find("ab",loc+1) 




Fortran:       SUBROUTINE STARTS(A,B)	
       CHARACTER*(*) A,B
        IF (INDEX(A,B).EQ.1) THEN	
          WRITE (6,*) ">",A,"< starts with >",B,"<"
         ELSE
          WRITE (6,*) ">",A,"< does not start with >",B,"<"
        END IF
      END SUBROUTINE STARTS

      SUBROUTINE HAS(A,B)	
       CHARACTER*(*) A,B
       INTEGER L
        L = INDEX(A,B)		
        IF (L.LE.0) THEN
          WRITE (6,*) ">",A,"< does not contain >",B,"<"
         ELSE
          WRITE (6,*) ">",A,"< contains a >",B,"<, offset",L
        END IF
      END SUBROUTINE HAS

      SUBROUTINE ENDS(A,B)	
       CHARACTER*(*) A,B
       INTEGER L
        L = LEN(A) - LEN(B)	
        IF (L.LT.0) THEN	
          WRITE (6,*) ">",A,"< is too short to end with >",B,"<"	
        ELSE IF (A(L + 1:L + LEN(B)).NE.B) THEN	
          WRITE (6,*) ">",A,"< does not end with >",B,"<"
        ELSE
          WRITE (6,*) ">",A,"< ends with >",B,"<"
        END IF
      END SUBROUTINE ENDS

      CALL STARTS("This","is")
      CALL STARTS("Theory","The")
      CALL HAS("Bananas","an")
      CALL ENDS("Banana","an")
      CALL ENDS("Banana","na")
      CALL ENDS("Brief","Much longer")
      END
Task: String matching








VB: Public Sub string_matching()
    word = "the"                                        
    sentence = "the last thing the man said was the"
    
     
    
    If InStr(1, sentence, word) = 1 Then
        Debug.Print "yes(1)"
    End If
    
    If Len(sentence) >= Len(word) _
        And Mid(sentence, 1, Len(word)) = word Then
        Debug.Print "yes(2)"
    End If
    
    If Len(sentence) >= Len(word) _
        And Mid(sentence, Len(sentence) - Len(word) + 1, Len(word)) = word Then
        Debug.Print "yes(3)"
    End If
    
    If Len(sentence) >= Len(word) _
    And InStr(Len(sentence) - Len(word) + 1, sentence, word) Then
        Debug.Print "yes(4)"
    End If
    
    r = InStr(1, sentence, word)
    Do While r <> 0
        Debug.Print r
        r = InStr(r + 1, sentence, word)
    Loop
End Sub



Fortran:       SUBROUTINE STARTS(A,B)	
       CHARACTER*(*) A,B
        IF (INDEX(A,B).EQ.1) THEN	
          WRITE (6,*) ">",A,"< starts with >",B,"<"
         ELSE
          WRITE (6,*) ">",A,"< does not start with >",B,"<"
        END IF
      END SUBROUTINE STARTS

      SUBROUTINE HAS(A,B)	
       CHARACTER*(*) A,B
       INTEGER L
        L = INDEX(A,B)		
        IF (L.LE.0) THEN
          WRITE (6,*) ">",A,"< does not contain >",B,"<"
         ELSE
          WRITE (6,*) ">",A,"< contains a >",B,"<, offset",L
        END IF
      END SUBROUTINE HAS

      SUBROUTINE ENDS(A,B)	
       CHARACTER*(*) A,B
       INTEGER L
        L = LEN(A) - LEN(B)	
        IF (L.LT.0) THEN	
          WRITE (6,*) ">",A,"< is too short to end with >",B,"<"	
        ELSE IF (A(L + 1:L + LEN(B)).NE.B) THEN	
          WRITE (6,*) ">",A,"< does not end with >",B,"<"
        ELSE
          WRITE (6,*) ">",A,"< ends with >",B,"<"
        END IF
      END SUBROUTINE ENDS

      CALL STARTS("This","is")
      CALL STARTS("Theory","The")
      CALL HAS("Bananas","an")
      CALL ENDS("Banana","an")
      CALL ENDS("Banana","na")
      CALL ENDS("Brief","Much longer")
      END
Task: String matching






PHP: <?php

$haystack = $_POST['haystack']; if ($haystack=='') {$haystack='no haystack given';}
$needle   = $_POST['needle'];   if ($needle=='')   {$needle='no needle given';}

function rexxpos($h,$n) {
  $pos = strpos($h,$n);
  if ($pos === false) { $pos=-1; }
  else                { $pos=$pos+1; }
  return ($pos);
 }

$pos=rexxpos($haystack,$needle);
$tx1 = "";
if ($pos==-1){ $n=0; }  // not found
else         { $n=1; }  // found once (so far)

if ($pos==1){ $tx1="needle found to be the start of the haystack"; }
if ($pos==strlen($haystack)-strlen($needle)+1)
            { $tx1="needle found at end of haystack"; }

if ($n>0) { // look for other occurrences
  $pl=$pos; // list of positions
  $p=$pos;  //
  $x="*************************************";
  $h=$haystack;
  while ($p>0) {
    $h=substr($x,0,$p).substr($h,$p);
    $p=rexxpos($h,$needle);
    if ( $p>0 ) { $n=$n+1; $pl=$pl.",&nbsp;".$p; }
  }
       if ($n==1) { $txt="needle found once in haystack, position: $pl."; }
  else if ($n==2) { $txt="needle found twice in haystack, position(s): $pl."; }
  else            { $txt="needle found $n times in haystack, position(s): $pl."; }
}
else              { $txt="needle not found in haystack."; }
?>
<html>
  <head>
    <title>Character Matching</title>
    <meta name="author" content="Walter Pachl">
    <meta name="date" content="02.05.2013">
    <style>
      p { font: 120% courier; }
    </style>
  </head>
  <body>
    <p><strong>Haystack:&nbsp;'<?php echo "$haystack" ?>'</strong></p>
    <p><strong>Needle:&nbsp;&nbsp;&nbsp;'<?php echo "$needle" ?>'</strong></p>
    <p><strong><?php echo "$txt" ?></strong></p>
    <!-- special message: -->
    <p  style="color: red";><strong><?php echo "$tx1" ?></strong></p>
  </body>
</html>





Fortran:       SUBROUTINE STARTS(A,B)	
       CHARACTER*(*) A,B
        IF (INDEX(A,B).EQ.1) THEN	
          WRITE (6,*) ">",A,"< starts with >",B,"<"
         ELSE
          WRITE (6,*) ">",A,"< does not start with >",B,"<"
        END IF
      END SUBROUTINE STARTS

      SUBROUTINE HAS(A,B)	
       CHARACTER*(*) A,B
       INTEGER L
        L = INDEX(A,B)		
        IF (L.LE.0) THEN
          WRITE (6,*) ">",A,"< does not contain >",B,"<"
         ELSE
          WRITE (6,*) ">",A,"< contains a >",B,"<, offset",L
        END IF
      END SUBROUTINE HAS

      SUBROUTINE ENDS(A,B)	
       CHARACTER*(*) A,B
       INTEGER L
        L = LEN(A) - LEN(B)	
        IF (L.LT.0) THEN	
          WRITE (6,*) ">",A,"< is too short to end with >",B,"<"	
        ELSE IF (A(L + 1:L + LEN(B)).NE.B) THEN	
          WRITE (6,*) ">",A,"< does not end with >",B,"<"
        ELSE
          WRITE (6,*) ">",A,"< ends with >",B,"<"
        END IF
      END SUBROUTINE ENDS

      CALL STARTS("This","is")
      CALL STARTS("Theory","The")
      CALL HAS("Bananas","an")
      CALL ENDS("Banana","an")
      CALL ENDS("Banana","na")
      CALL ENDS("Brief","Much longer")
      END
Task: String matching






PHP: <?php

$haystack = $_POST['haystack']; if ($haystack=='') {$haystack='no haystack given';}
$needle   = $_POST['needle'];   if ($needle=='')   {$needle='no needle given';}

function rexxpos($h,$n) {
  $pos = strpos($h,$n);
  if ($pos === false) { $pos=-1; }
  else                { $pos=$pos+1; }
  return ($pos);
 }

$pos=rexxpos($haystack,$needle);
$tx1 = "";
if ($pos==-1){ $n=0; }  // not found
else         { $n=1; }  // found once (so far)

if ($pos==1){ $tx1="needle found to be the start of the haystack"; }
if ($pos==strlen($haystack)-strlen($needle)+1)
            { $tx1="needle found at end of haystack"; }

if ($n>0) { // look for other occurrences
  $pl=$pos; // list of positions
  $p=$pos;  //
  $x="*************************************";
  $h=$haystack;
  while ($p>0) {
    $h=substr($x,0,$p).substr($h,$p);
    $p=rexxpos($h,$needle);
    if ( $p>0 ) { $n=$n+1; $pl=$pl.",&nbsp;".$p; }
  }
       if ($n==1) { $txt="needle found once in haystack, position: $pl."; }
  else if ($n==2) { $txt="needle found twice in haystack, position(s): $pl."; }
  else            { $txt="needle found $n times in haystack, position(s): $pl."; }
}
else              { $txt="needle not found in haystack."; }
?>
<html>
  <head>
    <title>Character Matching</title>
    <meta name="author" content="Walter Pachl">
    <meta name="date" content="02.05.2013">
    <style>
      p { font: 120% courier; }
    </style>
  </head>
  <body>
    <p><strong>Haystack:&nbsp;'<?php echo "$haystack" ?>'</strong></p>
    <p><strong>Needle:&nbsp;&nbsp;&nbsp;'<?php echo "$needle" ?>'</strong></p>
    <p><strong><?php echo "$txt" ?></strong></p>
    <!-- special message: -->
    <p  style="color: red";><strong><?php echo "$tx1" ?></strong></p>
  </body>
</html>
Task: String matching






PHP: <?php

$haystack = $_POST['haystack']; if ($haystack=='') {$haystack='no haystack given';}
$needle   = $_POST['needle'];   if ($needle=='')   {$needle='no needle given';}

function rexxpos($h,$n) {
  $pos = strpos($h,$n);
  if ($pos === false) { $pos=-1; }
  else                { $pos=$pos+1; }
  return ($pos);
 }

$pos=rexxpos($haystack,$needle);
$tx1 = "";
if ($pos==-1){ $n=0; }  // not found
else         { $n=1; }  // found once (so far)

if ($pos==1){ $tx1="needle found to be the start of the haystack"; }
if ($pos==strlen($haystack)-strlen($needle)+1)
            { $tx1="needle found at end of haystack"; }

if ($n>0) { // look for other occurrences
  $pl=$pos; // list of positions
  $p=$pos;  //
  $x="*************************************";
  $h=$haystack;
  while ($p>0) {
    $h=substr($x,0,$p).substr($h,$p);
    $p=rexxpos($h,$needle);
    if ( $p>0 ) { $n=$n+1; $pl=$pl.",&nbsp;".$p; }
  }
       if ($n==1) { $txt="needle found once in haystack, position: $pl."; }
  else if ($n==2) { $txt="needle found twice in haystack, position(s): $pl."; }
  else            { $txt="needle found $n times in haystack, position(s): $pl."; }
}
else              { $txt="needle not found in haystack."; }
?>
<html>
  <head>
    <title>Character Matching</title>
    <meta name="author" content="Walter Pachl">
    <meta name="date" content="02.05.2013">
    <style>
      p { font: 120% courier; }
    </style>
  </head>
  <body>
    <p><strong>Haystack:&nbsp;'<?php echo "$haystack" ?>'</strong></p>
    <p><strong>Needle:&nbsp;&nbsp;&nbsp;'<?php echo "$needle" ?>'</strong></p>
    <p><strong><?php echo "$txt" ?></strong></p>
    <!-- special message: -->
    <p  style="color: red";><strong><?php echo "$tx1" ?></strong></p>
  </body>
</html>






Ada: with Ada.Strings.Fixed;  use Ada.Strings.Fixed;
with Ada.Text_IO;        use Ada.Text_IO;

procedure Match_Strings is
   S1 : constant String := "abcd";
   S2 : constant String := "abab";
   S3 : constant String := "ab";
begin
   if S1'Length >= S3'Length and then S1 (S1'First..S1'First + S3'Length - 1) = S3 then
      Put_Line (''' & S1 & "' starts with '" & S3 & ''');
   end if;
   if S2'Length >= S3'Length and then S2 (S2'Last - S3'Length + 1..S2'Last) = S3 then
      Put_Line (''' & S2 & "' ends with '" & S3 & ''');
   end if;
   Put_Line (''' & S3 & "' first appears in '" & S1 & "' at" & Integer'Image (Index (S1, S3)));
   Put_Line
   (  ''' & S3 & "' appears in '" & S2 & ''' &
      Integer'Image (Ada.Strings.Fixed.Count (S2, S3)) & " times"
   );
end Match_Strings;
Task: Real constants and functions



C#: using System;

class Program {
    static void Main(string[] args) {        
        Console.WriteLine(Math.E); 
        Console.WriteLine(Math.PI); 
        Console.WriteLine(Math.Sqrt(10)); 
        Console.WriteLine(Math.Log(10)); 
        Console.WriteLine(Math.Log10(10)); 
        Console.WriteLine(Math.Exp(10)); 
        Console.WriteLine(Math.Abs(10)); 
        Console.WriteLine(Math.Floor(10.0)); 
        Console.WriteLine(Math.Ceiling(10.0)); 
        Console.WriteLine(Math.Pow(2, 5)); 
    }
}









Ada: Ada.Numerics.e  
Ada.Numerics.pi 
sqrt(x)         
log(x, base)    
exp(x)          
abs(x)          
S'floor(x)      
S'ceiling(x)    
x**y
Task: Real constants and functions

C: #include <math.h>

M_E; 
M_PI; 
sqrt(x); 
log(x); 
exp(x); 
abs(x); 
fabs(x); 
floor(x); 
ceil(x); 
pow(x,y); 











Ada: Ada.Numerics.e  
Ada.Numerics.pi 
sqrt(x)         
log(x, base)    
exp(x)          
abs(x)          
S'floor(x)      
S'ceiling(x)    
x**y
Task: Real constants and functions


C++: #include <iostream>
#include <cmath>

#ifdef M_E
static double euler_e = M_E;
#else
static double euler_e = std::exp(1); 
#endif

#ifdef M_PI
static double pi = M_PI;
#else
static double pi = std::acos(-1);
#endif

int main()
{
  std::cout << "e = " << euler_e
            << "\npi = " << pi
            << "\nsqrt(2) = " << std::sqrt(2.0)
            << "\nln(e) = " << std::log(euler_e)
            << "\nlg(100) = " << std::log10(100.0)
            << "\nexp(3) = " << std::exp(3.0)
            << "\n|-4.5| = " << std::abs(-4.5)   
            << "\nfloor(4.5) = " << std::floor(4.5)
            << "\nceiling(4.5) = " << std::ceil(4.5)
            << "\npi^2 = " << std::pow(pi,2.0) << std::endl;
}










Ada: Ada.Numerics.e  
Ada.Numerics.pi 
sqrt(x)         
log(x, base)    
exp(x)          
abs(x)          
S'floor(x)      
S'ceiling(x)    
x**y
Task: Real constants and functions




Go: package main

import (
    "fmt"
    "math"
    "math/big"
)

func main() {
    
    
    
    fmt.Println("float64 values:")
    fmt.Println("e:", math.E)
    fmt.Println("π:", math.Pi)

    

    
    fmt.Println("square root(1.44):", math.Sqrt(1.44))
    
    
    
    fmt.Println("ln(e):", math.Log(math.E))
    
    fmt.Println("exponential(1):", math.Exp(1))
    fmt.Println("absolute value(-1.2):", math.Abs(-1.2))
    fmt.Println("floor(-1.2):", math.Floor(-1.2))
    fmt.Println("ceiling(-1.2):", math.Ceil(-1.2))
    fmt.Println("power(1.44, .5):", math.Pow(1.44, .5))

    
    
    fmt.Println("\nfloat32 values:")
    fmt.Println("e:", float32(math.E))
    fmt.Println("π:", float32(math.Pi))

    
    
    
    
    
    
    
    pi := "3.141592653589793238462643383279502884197169399375105820974944"
    π, _, _ := big.ParseFloat(pi, 10, 200, 0)
    fmt.Println("\nbig.Float values:")
    fmt.Println("π:", π)
    
    x := new(big.Float).Neg(π)
    y := new(big.Float)
    fmt.Println("x:", x)
    fmt.Println("abs(x):", y.Abs(x))
}








Ada: Ada.Numerics.e  
Ada.Numerics.pi 
sqrt(x)         
log(x, base)    
exp(x)          
abs(x)          
S'floor(x)      
S'ceiling(x)    
x**y
Task: Real constants and functions





Java: Math.E; 
Math.PI; 
Math.sqrt(x); 
Math.log(x); 
Math.exp(x); 
Math.abs(x); 
Math.floor(x); 
Math.ceil(x); 
Math.pow(x,y); 







Ada: Ada.Numerics.e  
Ada.Numerics.pi 
sqrt(x)         
log(x, base)    
exp(x)          
abs(x)          
S'floor(x)      
S'ceiling(x)    
x**y
Task: Real constants and functions







Python: import math

math.e          
math.pi         
math.sqrt(x)    
math.log(x)     
math.log10(x)   
math.exp(x)     
abs(x)          
math.floor(x)   
math.ceil(x)    
x ** y          
pow(x, y[, n])  








Ada: Ada.Numerics.e  
Ada.Numerics.pi 
sqrt(x)         
log(x, base)    
exp(x)          
abs(x)          
S'floor(x)      
S'ceiling(x)    
x**y
Task: Real constants and functions

C: #include <math.h>

M_E; 
M_PI; 
sqrt(x); 
log(x); 
exp(x); 
abs(x); 
fabs(x); 
floor(x); 
ceil(x); 
pow(x,y);
Task: Real constants and functions



C#: using System;

class Program {
    static void Main(string[] args) {        
        Console.WriteLine(Math.E); 
        Console.WriteLine(Math.PI); 
        Console.WriteLine(Math.Sqrt(10)); 
        Console.WriteLine(Math.Log(10)); 
        Console.WriteLine(Math.Log10(10)); 
        Console.WriteLine(Math.Exp(10)); 
        Console.WriteLine(Math.Abs(10)); 
        Console.WriteLine(Math.Floor(10.0)); 
        Console.WriteLine(Math.Ceiling(10.0)); 
        Console.WriteLine(Math.Pow(2, 5)); 
    }
}