1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . IO ;
44using System . Net ;
@@ -80,13 +80,19 @@ public void getModule(string name)
8080 break ;
8181 }
8282
83- case "ui " :
83+ case "np " :
8484 {
8585 try
8686 {
87+ functions . Add ( "dot" , new ForNpDot ( ) ) ;
88+ functions . Add ( "exp" , new ForNpExp ( ) ) ;
8789 }
8890 catch
8991 {
92+ functions . Remove ( "dot" ) ;
93+ functions . Remove ( "exp" ) ;
94+ functions . Add ( "dot" , new ForNpDot ( ) ) ;
95+ functions . Add ( "exp" , new ForNpExp ( ) ) ;
9096 }
9197 break ;
9298 }
@@ -394,8 +400,7 @@ public Value execute(Value[] args)
394400 {
395401 if ( args . Length != 0 ) throw new Exception ( "Zero args expected" ) ;
396402 char key = Console . ReadKey ( true ) . KeyChar ;
397- //Console.ReadKey();
398- return ZERO ;
403+ return new UserValue ( key ) ;
399404 }
400405 }
401406
@@ -404,7 +409,6 @@ public class ForRandomInt : Function
404409 private static NumberValue ZERO = new NumberValue ( 0 ) ;
405410 public Value execute ( Value [ ] args )
406411 {
407- //Console.WriteLine(args.ToString());
408412 if ( args . Length != 2 ) throw new Exception ( "Two args expected" ) ;
409413 Random random = new Random ( ) ;
410414 NumberValue rand = new NumberValue ( random . Next ( int . Parse ( args [ 0 ] . ToString ( ) ) , int . Parse ( args [ 1 ] . ToString ( ) ) ) ) ;
@@ -1124,11 +1128,54 @@ public Value execute(Value[] args)
11241128 return ZERO ;
11251129 }
11261130 }
1131+
1132+ public class ForNpDot : Function
1133+ {
1134+ private static NumberValue ZERO = new NumberValue ( 0 ) ;
1135+
1136+ public Value execute ( Value [ ] args )
1137+ {
1138+ int n = args [ 0 ] . asNumber ( ) ;
1139+
1140+ double result = 0 ;
1141+
1142+ try
1143+ {
1144+ ArrayValue vector1 = ( ArrayValue ) Variables . get ( args [ 1 ] . ToString ( ) ) ;
1145+ ArrayValue vector2 = ( ArrayValue ) Variables . get ( args [ 2 ] . ToString ( ) ) ;
1146+ for ( int i = 0 ; i < n ; ++ i )
1147+ result += vector1 . get_by_index ( i ) . asNumber ( ) * vector2 . get_by_index ( i ) . asNumber ( ) ;
1148+ return new NumberValue ( result ) ;
1149+ }
1150+ catch
1151+ {
1152+ StackValue vector1 = ( StackValue ) Variables . get ( args [ 1 ] . ToString ( ) ) ;
1153+ StackValue vector2 = ( StackValue ) Variables . get ( args [ 2 ] . ToString ( ) ) ;
1154+
1155+ for ( int i = 0 ; i < n ; ++ i )
1156+ result += vector1 . get_by_index ( i ) . asNumber ( ) * vector2 . get_by_index ( i ) . asNumber ( ) ;
1157+ return new NumberValue ( result ) ;
1158+ }
1159+
1160+
1161+ //return new NumberValue(result);
1162+ }
1163+ }
1164+
1165+ public class ForNpExp : Function
1166+ {
1167+ private static NumberValue ZERO = new NumberValue ( 0 ) ;
1168+
1169+ public Value execute ( Value [ ] args )
1170+ {
1171+ return new NumberValue ( Math . Exp ( args [ 0 ] . asDouble ( ) ) ) ;
1172+ }
1173+ }
11271174}
11281175/*
11291176
11301177 This is the multiline comment.
11311178 Why?
11321179 IDK.
11331180
1134- */
1181+ */
0 commit comments